Java Object Deserialize deserialize(final byte[] inBytes)

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

Description

Deserialize an object.

License

Apache License

Parameter

Parameter Description
T the type parameter
inBytes The bytes to be deserialized

Return

the object

Declaration

public static <T> T deserialize(final byte[] inBytes) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;

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

public class Main {
    /**/*from w  w  w .j  av  a 2s  .  co m*/
     * Deserialize an object.
     * @param <T>  the type parameter
     * @param inBytes The bytes to be deserialized
     * @return the object
     * @since 5.0.0
     */
    public static <T> T deserialize(final byte[] inBytes) {
        final ByteArrayInputStream inputStream = new ByteArrayInputStream(inBytes);
        return deserialize(inputStream);
    }

    /**
     * Deserialize an object.
     * @param <T>  the type parameter
     * @param inputStream The stream to be deserialized
     * @return the object
     * @since 5.0.0
     */
    public static <T> T deserialize(final InputStream inputStream) {
        ObjectInputStream in = null;
        try {
            in = new ObjectInputStream(inputStream);
            final T obj = (T) in.readObject();
            return obj;
        } catch (final ClassNotFoundException | IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

Related

  1. deserialize(byte[] serializedData, int startPos, int length)
  2. deserialize(byte[] serializedObject)
  3. deserialize(byte[] sf)
  4. deserialize(final byte[] data)
  5. deserialize(final byte[] data)
  6. deserialize(final byte[] serialized)
  7. deserializeFromByte(byte[] value)
  8. deserializeFromByteArray(byte[] bytes)
  9. deserializeFromByteArray(byte[] encodedValue, String description)