Java InputStream Deserialize to Object deserialize(InputStream inputStream)

Here you can find the source of deserialize(InputStream inputStream)

Description

deserialize

License

Open Source License

Declaration

public static Object deserialize(InputStream inputStream) throws ClassNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*//  ww  w.ja v a  2 s  .  co  m
 * Copyright (C) 2008-2015 by Holger Arndt
 *
 * This file is part of the Universal Java Matrix Package (UJMP).
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * UJMP 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 2
 * of the License, or (at your option) any later version.
 *
 * UJMP 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 UJMP; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

import java.io.ByteArrayInputStream;

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

public class Main {
    public static Object deserialize(InputStream inputStream) throws ClassNotFoundException, IOException {
        ObjectInputStream in = null;
        try {
            // stream closed in the finally
            in = new ObjectInputStream(inputStream);
            return in.readObject();
        } catch (ClassNotFoundException ex) {
            throw ex;
        } catch (IOException ex) {
            throw ex;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                // ignore close exception
            }
        }
    }

    public static Object deserialize(byte[] data) throws ClassNotFoundException, IOException {
        ByteArrayInputStream bis = new ByteArrayInputStream(data);
        Object o = deserialize(bis);
        return o;
    }
}

Related

  1. deserialize(InputStream in)
  2. deserialize(InputStream in)
  3. deserialize(InputStream in, Class cls)
  4. deserialize(InputStream inputStream)
  5. deserialize(InputStream inputStream)
  6. deserialize(InputStream is)
  7. deserialize(InputStream is)
  8. deserialize(InputStream sourceInputStream, Class objectType)