Here you can find the source of deserialize(byte[] data)
Parameter | Description |
---|---|
data | binary array. |
Parameter | Description |
---|---|
IOException | if an I/O error occured. |
public static Object deserialize(byte[] data) throws IOException
//package com.java2s; /*//from ww w .ja v a 2s. co m * Copyright (c) 2001-2002, Marco Hunsicker. All rights reserved. * * This software is distributable under the BSD license. See the terms of the * BSD license in the documentation provided with this software. */ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; public class Main { /** * Deserializes an object previously written using an ObjectOutputStream. * * @param data binary array. * * @return deserialized object. * * @throws IOException if an I/O error occured. * * @see #serialize */ public static Object deserialize(byte[] data) throws IOException { if (data.length == 0) { return null; } return deserialize(new BufferedInputStream(new ByteArrayInputStream(data))); } /** * Deserializes the object stored in the given stream. * * @param in an input stream. * * @return the deserialized object. * * @throws IOException if an I/O exception occured. */ public static Object deserialize(InputStream in) throws IOException { ObjectInputStream oin = new ObjectInputStream(in); try { return oin.readObject(); } catch (ClassNotFoundException ex) { /** * @todo once we only support JDK 1.4, add chained exception */ throw new IOException(ex.getMessage()); } finally { if (oin != null) { oin.close(); } } } /** * Deserializes the object stored in the given file. * * @param file a file. * * @return the deserialized object. * * @throws IOException if an I/O exception occured. */ public static final Object deserialize(File file) throws IOException { return deserialize(new BufferedInputStream(new FileInputStream(file))); } }