Code example for InflaterInputStream

Methods: close, read

0
        FileOutputStream fos1 = new FileOutputStream(f1);
        DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
        dos1.write(byteArray, 2, 3);
        dos1.close();
        FileInputStream fis = new FileInputStream(f1);
        InflaterInputStream iis = new InflaterInputStream(fis);
        assertEquals("Incorrect Byte Returned.", 4, iis.read());
        assertEquals("Incorrect Byte Returned.", 7, iis.read());
        assertEquals("Incorrect Byte Returned.", 8, iis.read());
        assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
        assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
        iis.close();
        f1.delete();
 
        // Test for trying to write more bytes than available from the array 
        File f2 = new File("writeBII2.tst");
        FileOutputStream fos2 = new FileOutputStream(f2);
        DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
        try { 
            dos2.write(byteArray, 2, 10);
            fail("IndexOutOfBoundsException not thrown");