Java 8 Inflater - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Inflater class.

This code example shows how to use the following methods:end, inflate, setInput
    return "B1"; 
  } 
 
  protected byte[] decompress(byte input[], int len) {
    int olen = 0;
    Inflater decompresser = new Inflater();
    byte output[] = new byte[len];
    decompresser.setInput(input);
    try { 
      olen = decompresser.inflate(output);
    } catch(java.util.zip.DataFormatException e) {
    } 
    decompresser.end();
    if(len != olen) return new byte[0];
    return output;
  } 
 
  public NoitBundlev1() {} 
  public NoitBundlev1(String[] parts) throws Exception {
    super(parts);
8
CodeRank
This code example shows how to use the following methods:end, finished, inflate, setInput
 
    // This comes from the Apache Hive ORC code 
    private int decompressZip(Slice in)
            throws IOExceptionInflater inflater = new Inflater(true);
        try { 
            inflater.setInput((byte[]) in.getBase(), (int) (in.getAddress() - ARRAY_BYTE_BASE_OFFSET), in.length());
            allocateOrGrowBuffer(in.length() * EXPECTED_COMPRESSION_RATIO, false);
            int uncompressedLength = 0;
            while (true) { 
                uncompressedLength += inflater.inflate(buffer, uncompressedLength, buffer.length - uncompressedLength);
                if (inflater.finished() || buffer.length >= maxBufferSize) {
                    break; 
                } 
                int oldBufferSize = buffer.length;
                allocateOrGrowBuffer(buffer.length * 2, true);
                if (buffer.length <= oldBufferSize) {
                    throw new IllegalStateException(String.format("Buffer failed to grow. Old size %d, current size %d", oldBufferSize, buffer.length));
                } 

7
CodeRank
This code example shows how to use the following methods:finished, getBytesRead, getBytesWritten, getRemaining
     *  Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream 
     *  @since 0.8.9 
     */ 
    public long getTotalRead() { 
        try { 
            return inf.getBytesRead(); 
        } catch (Exception e) {
            return 0; 
        } 
    } 
 
    /** 
     *  Moved from i2ptunnel HTTPResponseOutputStream.InternalGZIPInputStream 
     *  @since 0.8.9 
     */ 
    public long getTotalExpanded() {  
        try { 
            return inf.getBytesWritten(); 
        } catch (Exception e) {
            // possible NPE in some implementations 

7
CodeRank
This code example shows how to use the following methods:end, getAdler, inflate, setInput
7
CodeRank
This code example shows how to use the following methods:inflate, reset, setInput
            out.add( in.readBytes( in.readableBytes() ) );
        } else 
        { 
            byte[] compressedData = new byte[ in.readableBytes() ];
            in.readBytes( compressedData );
            inflater.setInput( compressedData );
 
            byte[] data = new byte[ size ];
            inflater.inflate( data );
            out.add( Unpooled.wrappedBuffer( data ) );
            inflater.reset();
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:inflate, needsInput, setInput
This code example shows how to use the following methods:end, inflate, setInput
		 * Adding 0 add the dummy byte at the end of the input byte array. 
		 */ 
		byte[] inputWithDummyByteAdded = Arrays.copyOf(inputBytes, inputBytes.length + 1);
 
		// Set nowrap to true, to ignore the ZLIB headers 
		Inflater inflater = new Inflater(true);
		inflater.setInput(inputWithDummyByteAdded);
		int number_inflated_bytes = inflater.inflate(inflatedBytes);
		inflater.end();
		return Arrays.copyOf(inflatedBytes, number_inflated_bytes);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:end, inflate, setInput
        //Read frame data into array, and then put buffer back to where it was 
        int position = byteBuffer.position();
        byteBuffer.get(input, 0, realFrameSize);
        byteBuffer.position(position);
 
        Inflater decompresser = new Inflater();
        decompresser.setInput(input);
        try { 
            int inflatedTo = decompresser.inflate(result);
            logger.config(filename + ":Decompressed to " + inflatedTo + " bytes");
        } catch (DataFormatException dfe) {
            logger.log(Level.CONFIG, "Unable to decompress this frame:" + identifier, dfe);
 
            //Update position of main buffer, so no attempt is made to reread these bytes 
            byteBuffer.position(byteBuffer.position() + realFrameSize);
            throw new InvalidFrameException(ErrorMessage.ID3_UNABLE_TO_DECOMPRESS_FRAME.getMsg(identifier, filename, dfe.getMessage()));
        } 
        decompresser.end();
        return ByteBuffer.wrap(result);
    } 

6
CodeRank
This code example shows how to use the following methods:end
 
    @Override 
    public void end() { 
        super.end(); 
        releaseBuffer(); 
        decompressor.end();
    } 
 
    private void releaseBuffer() { 
        if (decompressed != null) {
            decompressed.release();
            decompressed = null;
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:inflate, reset, setInput
        Assert.assertEquals(longMsg.toString(), new String(output, 0, decompressed, "UTF-8"));
    } 
 
    @Test
    public void testEmptyFrames() throws Exception {
        decompress.reset();
 
        byte[] compressedFrame1 = { (byte)0xf2, (byte)0x48, (byte)0xcd };
        byte[] compressedFrame2 = { (byte)0xc9, (byte)0xc9, (byte)0x07, (byte)0x00 };
        byte[] compressedFrame3 = { (byte)0x00, (byte)0x00, (byte)0xff, (byte)0xff };
 
        byte[] output = new byte[1024];
 
        int decompressed = 0;
        decompress.setInput(compressedFrame1);
        decompressed = decompress.inflate(output, 0, output.length);
        Assert.assertEquals(2, decompressed);
        Assert.assertEquals("He", new String(output, 0, decompressed, "UTF-8"));
 
        decompress.setInput(compressedFrame2);

6
CodeRank

Related Java 8 Inflater Questions & Answers:

See Code Examples for Java 8 Inflater Methods: