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

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

Description

deserialize

License

Open Source License

Declaration

public static Serializable deserialize(byte[] array) 

Method Source Code


//package com.java2s;
/*/* w w  w .java 2 s  .c om*/
 * This file is part of SpoutPlugin.
 *
 * Copyright (c) 2011 Spout LLC <http://www.spout.org/>
 * SpoutPlugin is licensed under the GNU Lesser General Public License.
 *
 * SpoutPlugin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SpoutPlugin is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

import java.io.Serializable;

public class Main {
    private static ByteArrayInputStream byteInput;
    private static ObjectInputStream objectInput;

    public static Serializable deserialize(byte[] array) {
        if (array == null) {
            return null;
        }

        try {
            return deserializeRaw(array);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Serializable deserializeRaw(byte[] array) throws IOException, ClassNotFoundException {
        byteInput = new ByteArrayInputStream(array);
        objectInput = new ObjectInputStream(byteInput);
        Serializable o = (Serializable) objectInput.readObject();
        return o;
    }
}

Related

  1. deserialize(byte[] b)
  2. deserialize(byte[] blob)
  3. deserialize(byte[] buf)
  4. deserialize(byte[] buf)