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

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

Description

deserialize G Zip

License

Open Source License

Declaration

public static <T extends Externalizable> void deserializeGZip(byte[] buf, T obj) 

Method Source Code


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

import java.io.*;

import java.util.zip.GZIPInputStream;

public class Main {
    public static <T extends Externalizable> void deserializeGZip(byte[] buf, T obj) {
        try {// w w w  .j  a  v a 2 s.  c om
            deserializeGZipSafe(buf, obj);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static <T extends Externalizable> void deserializeGZipSafe(byte[] buf, T obj)
            throws IOException, ClassNotFoundException {
        ByteArrayInputStream bis = null;
        try {
            bis = new ByteArrayInputStream(buf);

            GZIPInputStream gzip = null;
            try {
                gzip = new GZIPInputStream(bis);

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

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

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

Related

  1. deserialize(String str)
  2. deSerialize(String str)
  3. deserializeAndCheckObject(final byte[] object, final Class type)
  4. deserialized(final byte[] data)
  5. deserializeFromString(String obj)
  6. deserializeJdk(byte[] bytes)
  7. deSerializeObj(byte[] array)
  8. deSerializeObject(byte[] base64SerializedObject)
  9. deserializeObject(String dir)