// creating the decompressed data
byte outPutBuf[] = new byte[500];
byte byteArray[] = { 1, 3, 4, 7, 8 };
int y = 0;
int x = 0;
Deflater deflate = new Deflater(1);
deflate.setInput(byteArray);
while (!(deflate.needsInput())) {
x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
}
deflate.finish();
while (!(deflate.finished())) {
x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
}
Inflater inflate = new Inflater();
byte outPutInf[] = new byte[500];
try {
while (!(inflate.finished())) {
if (inflate.needsInput()) {
inflate.setInput(outPutBuf);
}
y += inflate.inflate(outPutInf);
}
} catch (DataFormatException e) {
fail("Input to inflate is invalid or corrupted - getTotalIn");
}
assertTrue(
"the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
y == inflate.getTotalOut());
assertTrue(
"the total number of bytes to be compressed does not equal the total bytes decompressed",
inflate.getTotalOut() == deflate.getTotalIn());
// testing inflate(byte,int,int)
inflate.reset();
y = 0;
int offSet = 0;// seems only can start as 0
int length = 4;
try {
while (!(inflate.finished())) {
if (inflate.needsInput()) {
inflate.setInput(outPutBuf);
}
y += inflate.inflate(outPutInf, offSet, length);
}
} catch (DataFormatException e) {
System.out
.println("Input to inflate is invalid or corrupted - getTotalIn");
}
assertTrue(
"the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
y == inflate.getTotalOut());
assertTrue(
"the total number of bytes to be compressed does not equal the total bytes decompressed",
inflate.getTotalOut() == deflate.getTotalIn());
}