src/main/java/pw/phylame/util/ZLibUtils.java
/**
     * Decompresses a specified area of input data.
     * @param data the input byte data
     * @param offset start index of decompressing area
     * @param length length of decompression area
     * @return decompressed data
     */
Decompresses a specified area of input data.
@param data the input byte data
@param offset start index of decompressing area
@param length length of decompression area
@return decompressed data
Decompresses a specified area of input data . @param data the input byte data @param offset start index of decompressing area @param length length of decompression area @return decompressed data
public static byte[] decompress(byte[] data, int offset, int length) {
        byte[] output = new byte[0];
        Inflater decompresser = new Inflater();
        decompresser.reset();
        decompresser.setInput(data, offset, length);
        ByteArrayOutputStream o = new ByteArrayOutputStream(length);
        try {
            byte[] buf = new byte[BUFFER_SIZE];
            while (!decompresser.finished()) {
                int i = decompresser.inflate(buf);
                o.write(buf, 0, i);
            }
            output = o.toByteArray();
        } catch (Exception e) {
            output = Arrays.copyOfRange(data, offset, offset+length);
            e.printStackTrace();
        } finally {
            try {
                o.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        decompresser.end();
        return output;
    }
public static byte [ ] decompress ( byte [ ] data , int offset , int length ) { byte [ ] output = new byte [ 0 ] ; Inflater decompresser = new Inflater ( ) ; decompresser . reset ( ) ; decompresser . setInput ( data , offset , length ) ; ByteArrayOutputStream o = new ByteArrayOutputStream ( length ) ; try { byte [ ] buf = new byte [ BUFFER_SIZE ] ; while ( ! decompresser . finished ( ) ) { int i = decompresser . inflate ( buf ) ; o . write ( buf , 0 , i ) ; } output = o . toByteArray ( ) ; } catch ( Exception e ) { output = Arrays . copyOfRange ( data , offset , offset + length ) ; e . printStackTrace ( ) ; } finally { try { o . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } decompresser . end ( ) ; return output ; }
Decompresses a specified area of input data.
Decompresses a specified area of input data .