Java Object Deserialize deserializeObject(byte[] obj)

Here you can find the source of deserializeObject(byte[] obj)

Description

Deserializes an object from its byte format.

License

Open Source License

Parameter

Parameter Description
obj - The serialized format to deserialize.

Exception

Parameter Description
IOException If an error occurs with reading the object from the stream.
EOFException If an object is serialized and written through a stream, butthe array is cut off. When this object is deserialized, thereis no definite end to the object, which causes an EOF.
ClassNotFoundException If the serialized object's class cannot be found.

Return

The deserialized object.

Declaration

public static <T extends Serializable> T deserializeObject(byte[] obj)
        throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;

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

import java.io.Serializable;

public class Main {
    /**/*from  w  w  w.  ja va 2  s .  c om*/
     * Deserializes an object from its byte format.
     * 
     * @param obj
     *            - The serialized format to deserialize.
     * @return The deserialized object.
     * @throws IOException
     *             If an error occurs with reading the object from the stream.
     * @throws EOFException
     *             If an object is serialized and written through a stream, but
     *             the array is cut off. When this object is deserialized, there
     *             is no definite end to the object, which causes an EOF.
     * @throws ClassNotFoundException
     *             If the serialized object's class cannot be found.
     */
    public static <T extends Serializable> T deserializeObject(byte[] obj)
            throws IOException, ClassNotFoundException {
        try (ByteArrayInputStream in = new ByteArrayInputStream(obj)) {
            try (ObjectInputStream r = new ObjectInputStream(in)) {
                return (T) r.readObject();
            }
        }
    }
}

Related

  1. deserializeObject(byte[] bytes)
  2. deserializeObject(byte[] data)
  3. deSerializeObject(byte[] data)
  4. deserializeObject(byte[] data)
  5. deserializeObject(byte[] data, Class clazz)
  6. deserializeObject(byte[] serializedObj)
  7. deserializeObject(File file)
  8. deserializeObject(File inFile)
  9. deserializeObject(final byte[] b)