Here you can find the source of deserializeObject(byte[] obj)
Parameter | Description |
---|---|
obj | - The serialized format to deserialize. |
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. |
public static <T extends Serializable> T deserializeObject(byte[] obj) throws IOException, ClassNotFoundException
//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(); } } } }