Here you can find the source of deserialize(byte[] bytes)
Parameter | Description |
---|---|
bytes | The bytes or null |
Parameter | Description |
---|---|
IOException | In case of a reading or deserialization error |
ClassNotFoundException | In case an unknown class has been serialized |
public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException
//package com.java2s; /**//from ww w. ja va 2 s . co m * Copyright 2009-2016 Three Crickets LLC. * <p> * The contents of this file are subject to the terms of the LGPL version 3.0: * http://www.gnu.org/copyleft/lesser.html * <p> * Alternatively, you can obtain a royalty free commercial license with less * limitations, transferable or non-transferable, directly from Three Crickets * at http://threecrickets.com/ */ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; public class Main { /** * Deserializes an object. * * @param bytes * The bytes or null * @return The object or null * @throws IOException * In case of a reading or deserialization error * @throws ClassNotFoundException * In case an unknown class has been serialized */ public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException { if ((bytes == null) || (bytes.length == 0)) return null; ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes); try { ObjectInputStream stream = new ObjectInputStream(byteStream); try { return stream.readObject(); } finally { stream.close(); } } finally { byteStream.close(); } } }