Class ArchiveRecord
java.lang.Object
java.io.InputStream
org.archive.io.ArchiveRecord
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ARCRecord,HeaderedArchiveRecord,WARCRecord
Archive file Record.
- Version:
- $Date$ $Version$
- Author:
- stack
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MessageDigestCompute digest on what we read and add to metadata when done.protected booleanSet flag when we've reached the end-of-record.protected ArchiveRecordHeaderprotected InputStreamStream to read this record from.protected static final longMinimal http response or request header length.protected longPosition w/i the Record content, withinin.protected boolean -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.ArchiveRecord(InputStream in, ArchiveRecordHeader header) Constructor.ArchiveRecord(InputStream in, ArchiveRecordHeader header, int bodyOffset, boolean digest, boolean strict) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintThis available is not the stream's available.voidclose()Calling close on a record skips us past this record to the next record in the stream.voiddump()Writes output on STDOUT.voiddump(OutputStream os) Writes output on passedos.protected Stringprotected InputStreamgetIn()protected Stringprotected Stringlongprotected StringbooleanIs it likely that this record contains headers?protected voidprotected voidincrementPosition(long incr) protected booleanisEor()booleanisStrict()booleanprotected Stringintread()intread(byte[] b, int offset, int length) protected voidsetBodyOffset(int bodyOffset) protected voidsetEor(boolean eor) protected voidsetHeader(ArchiveRecordHeader header) voidsetStrict(boolean strict) protected voidskip()Skip over this records content.longskip(long n) Methods inherited from class java.io.InputStream
mark, read, reset
-
Field Details
-
MIN_HTTP_HEADER_LENGTH
protected static final long MIN_HTTP_HEADER_LENGTHMinimal http response or request header length. I've seen in arcs content length of 1 with no header. -
header
-
in
Stream to read this record from. Stream can only be read sequentially. Will only return this records' content returning a -1 if you try to read beyond the end of the current record.Streams can be markable or not. If they are, we'll be able to roll back when we've read too far. If not markable, assumption is that the underlying stream is managing our not reading too much (This pertains to the skipping over the end of the ARCRecord. See
skip(). -
position
protected long positionPosition w/i the Record content, withinin. This position is relative within this Record. Its not same as the Archive file position. -
eor
protected boolean eorSet flag when we've reached the end-of-record. -
digest
Compute digest on what we read and add to metadata when done. Currently hardcoded as sha-1. TODO: Remove when archive records digest or else, add a facility that allows the arc reader to compare the calculated digest to that which is recorded in the arc.Protected instead of private so subclasses can update and complete the digest.
-
strict
protected boolean strict
-
-
Constructor Details
-
ArchiveRecord
Constructor.- Parameters:
in- Stream cue'd up to be at the start of the record this instance is to represent.- Throws:
IOException
-
ArchiveRecord
Constructor.- Parameters:
in- Stream cue'd up to be at the start of the record this instance is to represent.header- Header data.- Throws:
IOException
-
ArchiveRecord
public ArchiveRecord(InputStream in, ArchiveRecordHeader header, int bodyOffset, boolean digest, boolean strict) throws IOException Constructor.- Parameters:
in- Stream cue'd up to be at the start of the record this instance is to represent.header- Header data.bodyOffset- Offset into the body. Usually 0.digest- True if we're to calculate digest for this record. Not digesting saves about ~15% of cpu during an ARC parse.strict- Be strict parsing (Parsing stops if ARC inproperly formatted).- Throws:
IOException
-
-
Method Details
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
getHeader
- Returns:
- Header data for this record.
-
setHeader
-
close
Calling close on a record skips us past this record to the next record in the stream. It does not actually close the stream. The underlying steam is probably being used by the next arc record.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Returns:
- Next character in this Record content else -1 if at EOR.
- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
available
public int available()This available is not the stream's available. Its an available based on what the stated Archive record length is minus what we've read to date.- Overrides:
availablein classInputStream- Returns:
- True if bytes remaining in record content.
-
skip
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
isStrict
public boolean isStrict()- Returns:
- Returns the strict.
-
setStrict
public void setStrict(boolean strict) - Parameters:
strict- The strict to set.
-
getIn
-
getDigestStr
-
incrementPosition
protected void incrementPosition() -
incrementPosition
protected void incrementPosition(long incr) -
getPosition
public long getPosition() -
isEor
protected boolean isEor() -
setEor
protected void setEor(boolean eor) -
getStatusCode4Cdx
-
getIp4Cdx
-
getDigest4Cdx
-
getMimetype4Cdx
-
outputCdx
- Throws:
IOException
-
dump
-
dump
Writes output on passedos.- Throws:
IOException
-
hasContentHeaders
public boolean hasContentHeaders()Is it likely that this record contains headers? This method will return true if the body is a http response that includes http response headers or the body is a http request that includes request headers, etc. Be aware that headers in content are distinct fromArchiveRecordHeader'headers'.- Returns:
- True if this Record's content has headers:
-
setBodyOffset
protected void setBodyOffset(int bodyOffset)
-