private void addArchiveEntry(final ArchiveOutputStream out, final String filename, final File infile)
throws IOException, FileNotFoundException {
final ArchiveEntry entry = out.createArchiveEntry(infile, filename);
out.putArchiveEntry(entry);
IOUtils.copy(new FileInputStream(infile), out);
out.closeArchiveEntry();
archiveList.add(filename);
}
|
private void testZipStreamWithImplodeCompression(final String filename, final String entryName) throws IOException {
final ZipArchiveInputStream zin = new ZipArchiveInputStream(new FileInputStream(new File(filename)));
final ZipArchiveEntry entry = zin.getNextZipEntry();
assertEquals("entry name", entryName, entry.getName());
assertTrue("entry can't be read", zin.canReadEntryData(entry));
assertEquals("method", ZipMethod.IMPLODING.getCode(), entry.getMethod());
final InputStream bio = new BoundedInputStream(zin, entry.getSize());
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final CheckedOutputStream out = new CheckedOutputStream(bout, new CRC32());
IOUtils.copy(bio, out);
out.flush();
assertEquals("CRC32", entry.getCrc(), out.getChecksum().getValue());
}
|
private void testExtraFlags(final int compressionLevel, final int flag) throws Exception {
final FileInputStream fis = new FileInputStream(getFile("test3.xml"));
byte[] content;
try {
content = IOUtils.toByteArray(fis);
} finally {
fis.close();
}
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final GzipParameters parameters = new GzipParameters();
parameters.setCompressionLevel(compressionLevel);
final GzipCompressorOutputStream out = new GzipCompressorOutputStream(bout, parameters);
IOUtils.copy(new ByteArrayInputStream(content), out);
out.flush();
out.close();
assertEquals("extra flags (XFL)", flag, bout.toByteArray()[8]);
}
|
public void testRemainingChunkTypes() throws Exception {
final FileInputStream isSz = new FileInputStream(getFile("mixed.txt.sz"));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
final FramedSnappyCompressorInputStream in = new FramedSnappyCompressorInputStream(isSz);
IOUtils.copy(in, out);
out.close();
} finally {
isSz.close();
}
assertArrayEquals(new byte[] { '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'5', '6', '7', '8', '9',
'5', '6', '7', '8', '9',
'5', '6', '7', '8', '9',
'5', '6', '7', '8', '9', 10,
'1', '2', '3', '4',
'1', '2', '3', '4',
}, out.toByteArray());
}
|