Java Object Deserialize deserializeFromByteArray(byte[] in)

Here you can find the source of deserializeFromByteArray(byte[] in)

Description

Utility method to deserialize Object from byte[].

License

Open Source License

Parameter

Parameter Description
in byte[] source

Return

Object deserialized

Declaration

public static Object deserializeFromByteArray(byte[] in) 

Method Source Code

//package com.java2s;
/* IoUtils/*ww w . j a  va 2  s  . c  om*/
 * 
 * Created on Dec 8, 2004
 *
 * Copyright (C) 2004 Internet Archive.
 * 
 * This file is part of the Heritrix web crawler (crawler.archive.org).
 * 
 * Heritrix is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * any later version.
 * 
 * Heritrix 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 Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License
 * along with Heritrix; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

public class Main {
    /**
     * Utility method to deserialize Object from  byte[]. 
     * 
     * @param in byte[] source
     * @return Object deserialized
     */
    public static Object deserializeFromByteArray(byte[] in) {
        Object object;
        try {
            ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(in));
            try {
                object = ois.readObject();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException(e);
            }
            ois.close();
        } catch (IOException e) {
            // shouldn't be possible
            throw new RuntimeException(e);
        }
        return object;
    }
}

Related

  1. deserialize(final byte[] inBytes)
  2. deserialize(final byte[] serialized)
  3. deserializeFromByte(byte[] value)
  4. deserializeFromByteArray(byte[] bytes)
  5. deserializeFromByteArray(byte[] encodedValue, String description)
  6. deserializeFromBytes(byte[] bytes, Class clazz)
  7. deserializeFromBytes(byte[] serialized, Class clazz)
  8. deserializeFromBytes(byte[] serializedObject)
  9. deserializeObject(byte[] buf)