Java Byte Array Uncompress uncompressByteArray(byte[] ubytes, String type)

Here you can find the source of uncompressByteArray(byte[] ubytes, String type)

Description

uncompress Byte Array

License

Open Source License

Declaration

public static byte[] uncompressByteArray(byte[] ubytes, String type) throws IOException 

Method Source Code


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

import java.io.*;
import java.util.*;

import java.util.zip.GZIPInputStream;

import java.util.zip.InflaterInputStream;

public class Main {
    public static byte[] uncompressByteArray(byte[] ubytes, String type) throws IOException {
        return uncompressAuxil(new ByteArrayInputStream(ubytes), type);
    }/*www  .j  a v a 2 s.c  om*/

    private static byte[] uncompressAuxil(InputStream input, String type) throws IOException {
        LinkedList<Byte> bytes = new LinkedList<Byte>();
        FilterInputStream filterInput;

        if (type != null && type.equals("gzip")) {
            filterInput = new GZIPInputStream(input);
        } else if (type != null && type.equals("deflate")) {
            filterInput = new InflaterInputStream(input);
        } else {
            filterInput = new PushbackInputStream(input);
        }

        byte[] buf = new byte[1000];
        int n;
        while ((n = filterInput.read(buf)) != -1) {
            for (int i = 0; i < n; i++) {
                bytes.add(buf[i]);
            }
        }
        int len = bytes.size();
        byte[] ungzipBytes = new byte[len];

        int j = 0;
        for (Byte b : bytes) {
            ungzipBytes[j++] = b;
        }
        return ungzipBytes;
    }
}

Related

  1. uncompress(byte[] input, int uncompr_len)
  2. uncompress(final byte[] buffer)
  3. uncompress(final byte[] compressedData)
  4. uncompress(final byte[] src)
  5. uncompressByte(byte[] content)
  6. uncompressByteArray(byte[] xmlByteArray)
  7. uncompressBytes(byte[] bytesToUncompress)
  8. uncompressGzip(byte[] b)
  9. uncompressObject(byte[] compressed)