Java Object Deserialize deserialize(byte[] bytes, boolean zipped)

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

Description

Deserialize a table of bytes to an Object instance.

License

Open Source License

Parameter

Parameter Description
bytes serialized representation of the object
zipped or not

Exception

Parameter Description
IOException the iO exception
ClassNotFoundException the class not found exception

Return

the Object created after

Declaration

public static Object deserialize(byte[] bytes, boolean zipped) throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
/*//from  w  ww.ja  v a 2  s .  com
 * Copyright (c) 2005-2016 Vincent Vandenschrick. All rights reserved.
 *
 *  This file is part of the Jspresso framework.
 *
 *  Jspresso 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.
 *
 *  Jspresso 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 Jspresso.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.ByteArrayInputStream;

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

import java.util.zip.GZIPInputStream;

public class Main {
    /**
     * Deserialize a table of bytes to an Object instance.
     *
     * @param bytes serialized representation of the object
     * @param zipped or not
     * @return the Object created after
     * @throws IOException the iO exception
     * @throws ClassNotFoundException the class not found exception
     */
    public static Object deserialize(byte[] bytes, boolean zipped) throws IOException, ClassNotFoundException {

        ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
        ObjectInputStream oi;
        if (zipped) {
            oi = new ObjectInputStream(new GZIPInputStream(bi));
        } else {
            oi = new ObjectInputStream(bi);
        }
        Object o = oi.readObject();
        oi.close();
        return o;
    }
}

Related

  1. deserialize(@Nonnull byte[] byteArray)
  2. deserialize(@Nullable final byte[] binaryInput)
  3. deserialize(byte[] bytes, Class clazz)
  4. deserialize(byte[] bytes, Class clazz)
  5. deserialize(byte[] bytes, Class klass)
  6. deserialize(byte[] bytes, final Class asClass)