Code example for DeflaterOutputStream

Methods: close, write

0
        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");
        } catch (IndexOutOfBoundsException e) {
        } 
 
        // Test for trying to write a negative number of bytes. 
        try { 
            dos2.write(byteArray, 2, Integer.MIN_VALUE);
            fail("IndexOutOfBoundsException not thrown");
        } catch (IndexOutOfBoundsException e) {
        } 
 
        // Test for trying to start writing from a byte < 0 from the array. 
        try { 
            dos2.write(byteArray, Integer.MIN_VALUE, 2);
            fail("IndexOutOfBoundsException not thrown");
        } catch (IndexOutOfBoundsException e) {
        } 
 
        // Test for trying to start writing from a byte > than the array 
        // size. 
        try { 
            dos2.write(byteArray, 10, 2);
            fail("IndexOutOfBoundsException not thrown");
        } catch (IndexOutOfBoundsException e) {
        } 
        dos2.close();
 
        // Not sure if this test is that important. 
        // Checks to see if you can write using the DeflaterOutputStream 
        // after 
        // the FileOutputStream has been closed.