mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-25 23:25:44 +00:00
FIX: Add ArchiveRecordHeader.getContentLength() to specifically return the warc/arc record content length,
not including headers
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user