Java Object Deserialize deserialize(byte[] in)

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

Description

deserialize

License

Apache License

Declaration

public static Object deserialize(byte[] in) 

Method Source Code


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

import java.io.*;

public class Main {
    public static Object deserialize(byte[] in) {
        return deserialize(in, Object.class);
    }/*from  w w w  .  j  a va 2  s .  c  o  m*/

    @SuppressWarnings("unchecked")
    public static <T> T deserialize(byte[] in, Class<T> requiredType) {
        Object rv = null;
        ByteArrayInputStream bis = null;
        ObjectInputStream is = null;
        try {
            if (in != null) {
                bis = new ByteArrayInputStream(in);
                is = new ObjectInputStream(bis);
                rv = is.readObject();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("deserialize error");
        } finally {
            close(is);
            close(bis);
        }
        return (T) rv;
    }

    private static void close(Closeable closeable) {
        if (closeable != null)
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("close stream error");
            }
    }
}

Related

  1. deserialize(byte[] data)
  2. deserialize(byte[] data)
  3. deserialize(byte[] data)
  4. deserialize(byte[] data)
  5. deserialize(byte[] features)
  6. deserialize(byte[] in)
  7. Deserialize(byte[] objectBytes)
  8. deserialize(byte[] objectData)
  9. deserialize(byte[] objectData)