Java Uncompress Byte Array uncompress(byte[] b)

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

Description

uncompress

License

Open Source License

Declaration

public static StringBuffer uncompress(byte[] b) 

Method Source Code

//package com.java2s;

import java.util.zip.DataFormatException;

import java.util.zip.Inflater;

public class Main {
    public static StringBuffer uncompress(byte[] b) {
        StringBuffer retval = new StringBuffer();
        Inflater infl = new Inflater();

        infl.setInput(b);//from w  ww .  j  a  v a 2 s  . c o  m
        int countUncompressed;
        byte[] buf = new byte[256];

        while (true) {
            try {
                countUncompressed = infl.inflate(buf);

                for (int i = 0; i < countUncompressed; i++) {
                    retval.append((char) buf[i]);
                }

                if (countUncompressed < buf.length) {
                    break;
                }
            } catch (DataFormatException dfe) {
                break;
            }
        }

        infl.end();
        return retval;
    }
}

Related

  1. degzip(byte[] compressed)
  2. uncompress(byte[] input)
  3. unzip(byte zipData[])
  4. unzip(byte[] blob)
  5. unzip(byte[] bytes)