GZIPStreamTestpublic class GZIPStreamTest extends TestCase Deflates and inflates some test data with GZipStreams |
Methods Summary |
---|
static void | createGZIP(java.io.ByteArrayOutputStream bytesOut)
GZIPOutputStream out = new GZIPOutputStream(bytesOut);
try {
byte[] input = makeSampleFile(1);
out.write(input, 0, input.length);
//out.finish();
} finally {
out.close();
}
| static byte[] | makeSampleFile(int stepStep)
byte[] sample = new byte[128 * 1024];
byte val, step;
int i, j, offset;
val = 0;
step = 1;
offset = 0;
for (i = 0; i < (128 * 1024) / 256; i++) {
for (j = 0; j < 256; j++) {
sample[offset++] = val;
val += step;
}
step += stepStep;
}
return sample;
| static void | scanGZIP(java.io.ByteArrayInputStream bytesIn)
GZIPInputStream in = new GZIPInputStream(bytesIn);
try {
ByteArrayOutputStream contents = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int len, totalLen = 0;
while ((len = in.read(buf)) > 0) {
contents.write(buf, 0, len);
totalLen += len;
}
assertEquals(totalLen, 128 * 1024);
} finally {
in.close();
}
| public void | testGZIPStream()
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
createGZIP(bytesOut);
byte[] zipData;
zipData = bytesOut.toByteArray();
/*
FileOutputStream outFile = new FileOutputStream("/tmp/foo.gz");
outFile.write(zipData, 0, zipData.length);
outFile.close();
*/
/*
FileInputStream inFile = new FileInputStream("/tmp/foo.gz");
int inputLength = inFile.available();
zipData = new byte[inputLength];
if (inFile.read(zipData) != inputLength)
throw new RuntimeException();
inFile.close();
*/
ByteArrayInputStream bytesIn = new ByteArrayInputStream(zipData);
scanGZIP(bytesIn);
|
|