public class TestGzipWriter_Cloning {
@Test
public void test_gzipwriter_cloning() {
InputStream in;
ByteCountingPushBackInputStream pbin;
GzipReader reader;
GzipWriter writer = null;
String in_file = "IAH-20080430204825-00000-blackbook.warc.gz";
RandomAccessFile raf;
RandomAccessFileOutputStream out;
try {
File out_file1 = File.createTempFile("jwat-testwrite3-", ".gz");
File out_file2 = File.createTempFile("jwat-testwrite4-", ".gz");
out_file1.deleteOnExit();
out_file2.deleteOnExit();
in = this.getClass().getClassLoader().getResourceAsStream(in_file);
pbin = new ByteCountingPushBackInputStream(in, 16);
reader = new GzipReader(pbin);
raf = new RandomAccessFile(out_file1, "rw");
raf.seek(0);
raf.setLength(0);
out = new RandomAccessFileOutputStream(raf);
writer = new GzipWriter(out);
cloneEntries(reader, writer);
pbin.close();
out.flush();
out.close();
raf.close();
Assert.assertTrue(reader.isCompliant());
Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
Assert.assertTrue(writer.isCompliant());
Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());
reader.close();
writer.close();
Assert.assertTrue(reader.isCompliant());
Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
Assert.assertTrue(writer.isCompliant());
Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());
in = this.getClass().getClassLoader().getResourceAsStream(in_file);
pbin = new ByteCountingPushBackInputStream(in, 16);
reader = new GzipReader(pbin, 8192);
raf = new RandomAccessFile(out_file2, "rw");
raf.seek(0);
raf.setLength(0);
out = new RandomAccessFileOutputStream(raf);
writer = new GzipWriter(out);
cloneEntries(reader, writer);
pbin.close();
out.flush();
out.close();
raf.close();
Assert.assertTrue(reader.isCompliant());
Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
Assert.assertTrue(writer.isCompliant());
Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());
reader.close();
writer.close();
Assert.assertTrue(reader.isCompliant());
Assert.assertEquals(reader.bIsCompliant, reader.isCompliant());
Assert.assertTrue(writer.isCompliant());
Assert.assertEquals(writer.bIsCompliant, writer.isCompliant());
in = this.getClass().getClassLoader().getResourceAsStream(in_file);
readEntriesOld(in);
raf = new RandomAccessFile(out_file1, "rw");
raf.seek(0);
in = new RandomAccessFileInputStream(raf);
pbin = new ByteCountingPushBackInputStream(in, 16);
reader = new GzipReader(pbin);
readEntries(reader);
pbin.close();
raf = new RandomAccessFile(out_file2, "rw");
raf.seek(0);
in = new RandomAccessFileInputStream(raf);
pbin = new ByteCountingPushBackInputStream(in, 16);
reader = new GzipReader(pbin, 8192);
readEntries(reader);
pbin.close();
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Exception not expected!");
}
}