Here you can find the source of deserialize(byte[] bytes)
Parameter | Description |
---|---|
bytes | byte array containing the object |
Parameter | Description |
---|---|
IOException | indicates that deserialization cannot be performed due to IOerror |
ClassNotFoundException | indicates that deserialization cannot be performed due to theabscence of suitable class |
public static Serializable deserialize(byte[] bytes) throws IOException, ClassNotFoundException
//package com.java2s; /**// w w w . jav a2 s . c om * Copyright 2007-2016, Kaazing Corporation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; public class Main { /** * Deserializes the object from byte array * * @param bytes * byte array containing the object * @return Deserialized object * @throws IOException * indicates that deserialization cannot be performed due to IO * error * @throws ClassNotFoundException * indicates that deserialization cannot be performed due to the * abscence of suitable class */ public static Serializable deserialize(byte[] bytes) throws IOException, ClassNotFoundException { try (ByteArrayInputStream b = new ByteArrayInputStream(bytes)) { try (ObjectInputStream o = new ObjectInputStream(b)) { return (Serializable) o.readObject(); } } } }