Code example for DeflaterOutputStream

Methods: finish, write

0
        // Need test to see if method finish() actually finishes 
        // Only testing possible errors, not if it actually works 
 
        File f1 = new File("finish.tst");
        FileOutputStream fos1 = new FileOutputStream(f1);
        DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
        byte byteArray[] = { 1, 3, 4, 6 };
        dos.write(byteArray);
        dos.finish();
 
        // Test to see if the same FileOutputStream can be used with the 
        // DeflaterOutputStream after finish is called. 
        try { 
            dos.write(1);
            fail("IOException not thrown");
        } catch (IOException e) {
        } 
 
        // Test for writing with a new FileOutputStream using the same 
        // DeflaterOutputStream. 
        FileOutputStream fos2 = new FileOutputStream(f1);