/**
* @tests java.util.zip.InflaterOutputStream#finish()
*/
public void test_finish() throws IOException {
InflaterOutputStream ios = new InflaterOutputStream(os);
ios.close();
try {
ios.finish();
fail("Should throw IOException");
} catch (IOException e) {
// expected
}
ios = new InflaterOutputStream(os);
ios.finish();
ios.finish();
ios.flush();
ios.flush();
ios.finish();
byte[] bytes1 = {10,20,30,40,50};
Deflater defaultDeflater = new Deflater(Deflater.BEST_SPEED);
defaultDeflater.setInput(bytes1);
defaultDeflater.finish();
int length1 = defaultDeflater.deflate(compressedBytes);
byte[] bytes2 = {100,90,80,70,60};
Deflater bestDeflater = new Deflater(Deflater.BEST_COMPRESSION );
bestDeflater.setInput(bytes2);
bestDeflater.finish();
int length2 = bestDeflater.deflate(compressedBytes,length1,compressedBytes.length-length1);
ios = new InflaterOutputStream(os);
for (int i = 0; i < length1; i++) {
ios.write(compressedBytes[i]);
}
ios.finish();
ios.close();
byte[] result = os.toByteArray();
for(int i =0;i<bytes1.length; i++){
assertEquals(bytes1[i],result[i]);
}
ios = new InflaterOutputStream(os);
for (int i = length1; i < length2*2; i++) {
ios.write(compressedBytes[i]);
}
ios.finish();
ios.close();
result = os.toByteArray();
for(int i =0;i<bytes2.length; i++){
assertEquals(bytes2[i],result[bytes1.length+i]);
}