warnings = 0;
url = this.getClass().getClassLoader().getResource(warcFile);
file = new File(getUrlPath(url));
ram = new RandomAccessFile(file, "r");
in = new RandomAccessFileInputStream(ram);
reader = WarcReaderFactory.getReaderCompressed(in);
reader.setBlockDigestEnabled( bDigest );
Assert.assertTrue(reader.setBlockDigestAlgorithm( "sha1" ));
reader.setPayloadDigestEnabled( bDigest );
Assert.assertTrue(reader.setPayloadDigestAlgorithm( "sha1" ));
for (int i=0; i<entries.size(); ++i) {
entry = entries.get(i);
try {
reader.getNextRecordFrom(in, entry.offset);
Assert.fail("Exception expected!");
} catch (IllegalStateException e) {
}
try {
reader.getNextRecordFrom(in, entry.offset, 8192);
Assert.fail("Exception expected!");
} catch (IllegalStateException e) {
}
if ((record = reader.getNextRecord()) != null) {
if (bDebugOutput) {
TestBaseUtils.printRecord(record);
TestBaseUtils.printRecordErrors(record);
}
record.close();
consumed += record.getConsumed();
Assert.assertEquals(record.consumed, record.getConsumed());
// Test content-type and http response/request
if (record.header.contentType != null) {
if ("application".equals(record.header.contentType.contentType)
&& "http".equals(record.header.contentType.mediaType)) {
if ("response".equals(record.header.contentType.getParameter("msgtype"))) {
Assert.assertNotNull(record.payload);
Assert.assertNotNull(record.httpHeader);
Assert.assertEquals(HttpHeader.HT_RESPONSE, record.httpHeader.headerType);
} else if ("request".equals(record.header.contentType.getParameter("msgtype"))) {
Assert.assertNotNull(record.payload);
Assert.assertNotNull(record.httpHeader);
Assert.assertEquals(HttpHeader.HT_REQUEST, record.httpHeader.headerType);
}
}
}
if ( bDigest ) {
if ( (record.payload != null && record.computedBlockDigest == null)
|| (record.httpHeader != null && record.computedPayloadDigest == null) ) {
Assert.fail( "Digest missing!" );
}
}
++records;
if (record.diagnostics.hasErrors()) {
errors += record.diagnostics.getErrors().size();
}
if (record.diagnostics.hasWarnings()) {
warnings += record.diagnostics.getWarnings().size();
}
if (record.header.warcRecordIdUri.compareTo(entry.recordId) != 0) {
Assert.fail("Wrong record");
}
} else {
Assert.fail("Location incorrect");
}
}
record = reader.getNextRecord();
Assert.assertNull(record);
url = this.getClass().getClassLoader().getResource(warcFile2);
file = new File(getUrlPath(url));
Assert.assertEquals(ram.length(), reader.getConsumed());
Assert.assertEquals(ram.length(), reader.getOffset());
Assert.assertEquals(file.length(), consumed);
reader.close();
Assert.assertEquals(ram.length(), reader.getConsumed());
Assert.assertEquals(ram.length(), reader.getOffset());
Assert.assertEquals(file.length(), consumed);
in.close();
ram.close();
if (bDebugOutput) {
TestBaseUtils.printStatus(records, errors, warnings);
}
Assert.assertEquals(expected_records, records);
Assert.assertEquals(0, errors);
Assert.assertEquals(0, warnings);
/*
* getReaderUncompressed(in, buffer_size) / getNextRecord().
*/
records = 0;
consumed = 0;
errors = 0;
warnings = 0;
url = this.getClass().getClassLoader().getResource(warcFile);
file = new File(getUrlPath(url));
ram = new RandomAccessFile(file, "r");
in = new RandomAccessFileInputStream(ram);
reader = WarcReaderFactory.getReaderCompressed(in, 8192);
reader.setBlockDigestEnabled( bDigest );
Assert.assertTrue(reader.setBlockDigestAlgorithm( "sha1" ));