public class TestWarcReaderFactory_IsWarc {
@Test
public void test_iswarc() {
byte[] bytes;
ByteCountingPushBackInputStream pbin;
try {
/*
* isWarcFile.
*/
bytes = WarcConstants.WARC_MAGIC_HEADER.getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertTrue(WarcReaderFactory.isWarcFile(pbin));
pbin.close();
bytes = "WARC/1.0".getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertTrue(WarcReaderFactory.isWarcFile(pbin));
pbin.close();
bytes = WarcConstants.WARC_MAGIC_HEADER.toLowerCase().getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertFalse(WarcReaderFactory.isWarcFile(pbin));
pbin.close();
bytes = "warc/1.0".getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertFalse(WarcReaderFactory.isWarcFile(pbin));
pbin.close();
bytes = "WARC".getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertFalse(WarcReaderFactory.isWarcFile(pbin));
pbin.close();
/*
* isWarcRecord.
*/
bytes = WarcConstants.WARC_MAGIC_HEADER.getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertTrue(WarcReaderFactory.isWarcRecord(pbin));
pbin.close();
bytes = "WARC/1.0".getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertTrue(WarcReaderFactory.isWarcRecord(pbin));
pbin.close();
bytes = WarcConstants.WARC_MAGIC_HEADER.toLowerCase().getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertFalse(WarcReaderFactory.isWarcRecord(pbin));
pbin.close();
bytes = "warc/1.0".getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertFalse(WarcReaderFactory.isWarcRecord(pbin));
pbin.close();
bytes = "WARC".getBytes();
pbin = new ByteCountingPushBackInputStream(new ByteArrayInputStream(bytes), WarcReaderFactory.PUSHBACK_BUFFER_SIZE);
Assert.assertFalse(WarcReaderFactory.isWarcRecord(pbin));
pbin.close();
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Exception not expected!");
}
}