Code example for Inflater

0
public class DeflaterTest extends TestCase {
 
    private byte[] compressed = new byte[32];
    private byte[] decompressed = new byte[20];
    private Deflater deflater = new Deflater();
    private Inflater inflater = new Inflater();
    private int totalDeflated = 0;
    private int totalInflated = 0;
 
    public void testDeflate() throws DataFormatException { 
        deflater.setInput(new byte[] { 1, 2, 3 });
        deflateInflate(Deflater.NO_FLUSH); 
        assertTrue(totalInflated < 3);
        assertEquals(0, decompressed[2]); // the 3rd byte shouldn't have been flushed yet
 
        deflater.setInput(new byte[] { 4, 5, 6 });
        deflateInflate(Deflater.SYNC_FLUSH); 
        assertEquals(6, totalInflated);
        assertDecompressed(1, 2, 3, 4, 5, 6); 
        assertEquals(0, inflater.inflate(decompressed));