Java Object Serialize and Deserialize deserializeSafe(byte[] buf, T obj)

Here you can find the source of deserializeSafe(byte[] buf, T obj)

Description

deserialize Safe

License

Open Source License

Declaration

public static <T extends Externalizable> void deserializeSafe(byte[] buf, T obj)
            throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static <T extends Externalizable> void deserializeSafe(byte[] buf, T obj)
            throws IOException, ClassNotFoundException {
        ByteArrayInputStream bis = null;
        try {/*ww  w.  ja v a 2s  . c  om*/
            bis = new ByteArrayInputStream(buf);

            ObjectInputStream oin = null;
            try {
                oin = new ObjectInputStream(bis);
                obj.readExternal(oin);
            } finally {
                if (oin != null) {
                    try {
                        oin.close();
                    } catch (IOException e) {
                        /* NOP */ }
                }
            }

        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                    /* NOP */ }
            }
        }
    }
}

Related

  1. deSerializeObject(String str, Class cls)
  2. deserializeObjectFromByteArray(byte[] data)
  3. deserializeObjectFromByteArray(byte[] theSerializedVersion)
  4. deserializeProperties(byte[] bytes)
  5. deserializeRaw(byte[] array)
  6. deserializeShort(byte[] inbuf, int offset)
  7. deserializeStream(final String witness)
  8. serializeAndDeserialize(Object o)
  9. serializeAndDeserialize(Object o)