Java Byte Array to Object deserialize(byte[] bytes)

Here you can find the source of deserialize(byte[] bytes)

Description

Deserializes the object from byte array

License

Open Source License

Parameter

Parameter Description
bytes byte array containing the object

Exception

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

Return

Deserialized object

Declaration

public static Serializable deserialize(byte[] bytes) throws IOException, ClassNotFoundException 

Method Source Code

//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();
            }
        }
    }
}

Related

  1. deserialize(byte[] buffer, int count)
  2. deserialize(byte[] byteArray)
  3. deserialize(byte[] byteArray)
  4. deserialize(byte[] bytes)
  5. deserialize(byte[] bytes)
  6. deserialize(byte[] bytes)
  7. deserialize(byte[] bytes)
  8. deserialize(byte[] bytes)
  9. deserialize(byte[] bytes)