Java Byte Array to Object deserialize(byte[] blob)

Here you can find the source of deserialize(byte[] blob)

Description

Deserialise the specified blob into an Object and return it to the client.

License

Open Source License

Parameter

Parameter Description
blob - the blob of bytes to deserialize

Exception

Parameter Description
IOException - if it cannot deseriliaze
IllegalArgumentException if the blob is null

Return

Object - the object to return

Declaration

static public Object deserialize(byte[] blob) throws IOException,
        ClassNotFoundException 

Method Source Code

//package com.java2s;
import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

public class Main {
    /**/*from  w ww .  jav a2  s .co  m*/
     * Deserialise the specified blob into an Object and return it
     * to the client.
     * <p>
     * If there is an error with the deserialization then throw an
     * IOException
     *
     * @param blob - the blob of bytes to deserialize
     * @return Object - the object to return
     * @throws IOException - if it cannot deseriliaze
     * @throws IllegalArgumentException if the blob is null
     */
    static public Object deserialize(byte[] blob) throws IOException,
            ClassNotFoundException {

        if (blob == null) {
            throw new IllegalArgumentException("null blob to deserialize");
        }

        ByteArrayInputStream bstream = new ByteArrayInputStream(blob);
        ObjectInputStream istream = new ObjectInputStream(bstream);

        return istream.readObject();
    }
}

Related

  1. deserialize(byte[] array)
  2. deserialize(byte[] b)
  3. deserialize(byte[] buf)
  4. deserialize(byte[] buf)
  5. deserialize(byte[] buffer, int count)
  6. deserialize(byte[] byteArray)