FIX: Add ArchiveRecordHeader.getContentLength() to specifically return the warc/arc record content length,

not including headers
This commit is contained in:
Ilya Kreymer
2013-06-21 14:56:31 -07:00
parent b85828135b
commit 3916175e4d
4 changed files with 28 additions and 2 deletions
@@ -38,6 +38,12 @@ public interface ArchiveRecordHeader {
* @return Return length of record.
*/
public abstract long getLength();
/**
* @return Return Content-Length of the contents of the record
*/
public abstract long getContentLength();
/**
* @return Record subject-url.
@@ -129,6 +129,14 @@ public class ARCRecordMetaData implements ArchiveRecordHeader, ARCConstants {
return Long.parseLong((String)this.headerFields.
get(LENGTH_FIELD_KEY));
}
/**
* @return Return Content-Length of the contents of the record
* Same as record length for arcs? TODO
*/
public long getContentLength() {
return getLength();
}
/**
* @return Header url.
@@ -168,14 +168,21 @@ public class WARCRecord extends ArchiveRecord implements WARCConstants {
return this.headers.get(key);
}
public long getLength() {
// Returns just the Content-Length of the warc record
public long getContentLength() {
Object o = this.headers.get(CONTENT_LENGTH);
if (o == null) {
return -1;
}
long contentLength = (o instanceof Long)?
((Long)o).longValue(): Long.parseLong((String)o);
return contentLength + contentOffset;
return contentLength;
}
// Returns the full record length
public long getLength()
{
return getContentLength() + contentOffset;
}
public String getMimetype() {
@@ -82,6 +82,7 @@ public class HeaderedArchiveRecordTest extends TestCase {
public void testParseHttpHeadersInARC() throws IOException {
final int len = HTTPHEADER.length() + BODY.length();
final int contentLength = BODY.length();
final String url = "http://www.ly.gov.tw:80/accpart.htm";
final String hdr = HTTPHEADER + BODY;
// Interesting difference between ARCRecord and WARCRecord is that the
@@ -122,6 +123,10 @@ public class HeaderedArchiveRecordTest extends TestCase {
public long getLength() {
return len;
}
public long getContentLength() {
return contentLength;
}
public String getMimetype() {
return null;