Java Utililty Methods Decompress Byte Array

List of utility methods to do Decompress Byte Array

Description

The list of methods to do Decompress Byte Array are organized into topic(s).

Method

byte[]decompressBytes(byte[] input)
decompress Bytes
Inflater ifl = new Inflater(); 
ifl.setInput(input);
ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length);
byte[] buff = new byte[1024];
while (!ifl.finished()) {
    int count = ifl.inflate(buff);
    baos.write(buff, 0, count);
baos.close();
byte[] output = baos.toByteArray();
return output;
byte[]decompressByZLIB(byte[] compressedBytes)
Uncompresses the given byte array by the ZLIB algorithm.
try {
    Inflater inflater = new Inflater();
    inflater.setInput(compressedBytes);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(compressedBytes.length);
    byte[] buffer = new byte[1024];
    while (!inflater.finished()) {
        int count = inflater.inflate(buffer);
        byteArrayOutputStream.write(buffer, 0, count);
...
byte[]decompressData(byte[] compressedInput)
decompress Data
Inflater decompressor = new Inflater();
decompressor.setInput(compressedInput);
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedInput.length);
byte[] buffer = new byte[1024]; 
while (!decompressor.finished()) {
    int count = decompressor.inflate(buffer);
    bos.write(buffer, 0, count);
bos.close();
return bos.toByteArray();
voiddecompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
Decompresses a given byte array that is a compressed folder.
ZipInputStream zipFile = new ZipInputStream(new ByteArrayInputStream(folderAsCompressedArray));
ZipEntry ze = null;
final int minusOne = -1;
while ((ze = zipFile.getNextEntry()) != null) {
    FileOutputStream fout = new FileOutputStream(
            new File(unzippedLocation, ze.getName()).getAbsolutePath());
    for (int c = zipFile.read(); c != minusOne; c = zipFile.read()) {
        fout.write(c);
...
byte[]decompressGzip(byte[] compressed)
decompress Gzip
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(bis);
try {
    byte[] buffer = new byte[READ_BUFFER_SIZE];
    int read = 0;
    while ((read = gis.read(buffer)) != -1) {
        bos.write(buffer, 0, read);
...
byte[]decompressGZIP(byte[] data)
decompress GZIP
byte[] uncompressedBytes = new byte[1000000];
InputStream inputStream = new ByteArrayInputStream(data);
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPInputStream gzip = new GZIPInputStream(inputStream);
int len;
while ((len = gzip.read(uncompressedBytes)) > 0) {
    out.write(uncompressedBytes, 0, len);
gzip.close();
inputStream.close();
return out.toByteArray();
byte[]decompressGzipByteArray(byte[] compressedByteArray)
decompress a gzip byte array, using a default buffer length of 1024

return decompressGzipByteArray(compressedByteArray, 1024);
ObjectdecompressObject(byte[] bytes)
decompress Object
return (new ObjectInputStream(new InflaterInputStream(new ByteArrayInputStream(bytes)))).readObject();
StringdecompressString(byte[] compressed)
GZIP de-compresses the data
if (compressed != null) {
    try (ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
            GZIPInputStream gis = new GZIPInputStream(bis);
            BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"))) {
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
...
StringdecompressString(byte[] compressedData)
decompress String
Inflater decompressor = new Inflater();
decompressor.setInput(compressedData);
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
byte[] buf = new byte[1024];
while (!decompressor.finished()) {
    try {
        int count = decompressor.inflate(buf);
        bos.write(buf, 0, count);
...