Here you can find the source of deserialize(byte[] objectData)
Deserializes a single Object
from an array of bytes.
Parameter | Description |
---|---|
objectData | the serialized object, must not be null |
Parameter | Description |
---|---|
IllegalArgumentException | if <code>objectData</code> is <code>null</code> |
RuntimeException | (runtime) if the serialization fails |
public static Object deserialize(byte[] objectData)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; public class Main { /**/*from www . j a v a 2s . c om*/ * <p>Deserializes a single <code>Object</code> from an array of bytes.</p> * * @param objectData the serialized object, must not be null * @return the deserialized object * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code> * @throws RuntimeException (runtime) if the serialization fails */ public static Object deserialize(byte[] objectData) { if (objectData == null) throw new IllegalArgumentException( "The byte[] must not be null"); ByteArrayInputStream bais = new ByteArrayInputStream(objectData); return deserialize(bais); } /** * <p>Deserializes an <code>Object</code> from the specified stream.</p> * * <p>The stream will be closed once the object is written. This * avoids the need for a finally clause, and maybe also exception * handling, in the application code.</p> * * <p>The stream passed in is not buffered internally within this method. * This is the responsibility of your application if desired.</p> * * @param inputStream the serialized object input stream, must not be null * @return the deserialized object * @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code> * @throws RuntimeException (runtime) if the serialization fails */ public static Object deserialize(InputStream inputStream) { if (inputStream == null) throw new IllegalArgumentException( "The InputStream must not be null"); ObjectInputStream in = null; try { // stream closed in the finally in = new ObjectInputStream(inputStream); return in.readObject(); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } finally { try { if (in != null) in.close(); } catch (IOException ex) { // ignore close exception } } } }