Java Object Deserialize deserialize(@Nullable final byte[] binaryInput)

Here you can find the source of deserialize(@Nullable final byte[] binaryInput)

Description

deserialize

License

Apache License

Declaration

@Nullable
    public static Object deserialize(@Nullable final byte[] binaryInput) 

Method Source Code


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

import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;

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

public class Main {
    @Nullable
    public static Object deserialize(@Nullable final byte[] binaryInput) {
        return (binaryInput != null) ? deserialize(new ByteArrayInputStream(binaryInput)) : null;
    }/*from  w w w. j a v a 2 s . co  m*/

    @Nullable
    public static Object deserialize(@Nullable final InputStream binaryInput) {
        if (null == binaryInput) {
            return null;
        }
        try {
            ObjectInputStream in = new ObjectInputStream(binaryInput);
            try {
                return in.readObject();
            } finally {
                in.close();
            }
        } catch (IOException ex) {
            throw new IllegalStateException("Unable to read in persisted object", ex);
        } catch (ClassNotFoundException ex) {
            throw new IllegalStateException("Unable to load class for persisted object", ex);
        }
    }
}

Related

  1. deserialize(@Nonnull byte[] byteArray)
  2. deserialize(byte[] bytes, boolean zipped)
  3. deserialize(byte[] bytes, Class clazz)
  4. deserialize(byte[] bytes, Class clazz)
  5. deserialize(byte[] bytes, Class klass)