Java Byte Array Uncompress uncompress(final byte[] src)

Here you can find the source of uncompress(final byte[] src)

Description

uncompress

License

Apache License

Declaration

public static byte[] uncompress(final byte[] src) throws IOException 

Method Source Code


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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.util.zip.InflaterInputStream;

public class Main {
    public static byte[] uncompress(final byte[] src) throws IOException {
        byte[] result = src;
        byte[] uncompressData = new byte[src.length];
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(src);
        InflaterInputStream inflaterInputStream = new InflaterInputStream(byteArrayInputStream);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);

        try {//from www  .ja va2 s  .c o  m
            while (true) {
                int len = inflaterInputStream.read(uncompressData, 0, uncompressData.length);
                if (len <= 0) {
                    break;
                }
                byteArrayOutputStream.write(uncompressData, 0, len);
            }
            byteArrayOutputStream.flush();
            result = byteArrayOutputStream.toByteArray();
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                byteArrayInputStream.close();
            } catch (IOException e) {
            }
            try {
                inflaterInputStream.close();
            } catch (IOException e) {
            }
            try {
                byteArrayOutputStream.close();
            } catch (IOException e) {
            }
        }

        return result;
    }
}

Related

  1. uncompress(byte[] data)
  2. uncompress(byte[] gzData, String charset)
  3. uncompress(byte[] input, int uncompr_len)
  4. uncompress(final byte[] buffer)
  5. uncompress(final byte[] compressedData)
  6. uncompressByte(byte[] content)
  7. uncompressByteArray(byte[] ubytes, String type)
  8. uncompressByteArray(byte[] xmlByteArray)
  9. uncompressBytes(byte[] bytesToUncompress)