public abstract class ArchiveReader extends Object implements ArchiveFileConstants, Iterable<ArchiveRecord>, Closeable
ArchiveRecords.| Modifier and Type | Class and Description |
|---|---|
protected class |
ArchiveReader.ArchiveRecordIterator
Inner ArchiveRecord Iterator class.
|
| Modifier and Type | Field and Description |
|---|---|
protected InputStream |
in
Archive file input stream.
|
static int |
MAX_ALLOWED_RECOVERABLES
Maximum amount of recoverable exceptions in a row.
|
ABSOLUTE_OFFSET_KEY, CDX, CDX_FILE, CDX_LINE_BUFFER_SIZE, CRLF, DATE_FIELD_KEY, DEFAULT_DIGEST_METHOD, DOT_COMPRESSED_FILE_EXTENSION, DUMP, GZIP_DUMP, HEADER, INVALID_SUFFIX, LENGTH_FIELD_KEY, MIMETYPE_FIELD_KEY, NOHEAD, OCCUPIED_SUFFIX, READER_IDENTIFIER_FIELD_KEY, RECORD_IDENTIFIER_FIELD_KEY, SINGLE_SPACE, TYPE_FIELD_KEY, URL_FIELD_KEY, VERSION_FIELD_KEY| Modifier | Constructor and Description |
|---|---|
protected |
ArchiveReader() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cdxOutput(boolean toFile) |
protected void |
cleanupCurrentRecord()
Cleanout the current record if there is one.
|
void |
close() |
protected abstract ArchiveRecord |
createArchiveRecord(InputStream is,
long offset)
Return an Archive Record homed on
offset into
is. |
protected ArchiveRecord |
currentRecord(ArchiveRecord r) |
abstract void |
dump(boolean compress)
Dump this file on STDOUT
|
ArchiveRecord |
get() |
ArchiveRecord |
get(long offset)
Get record at passed
offset. |
protected ArchiveRecord |
getCurrentRecord() |
abstract ArchiveReader |
getDeleteFileOnCloseReader(File f) |
abstract String |
getDotFileExtension() |
abstract String |
getFileExtension() |
String |
getFileName() |
protected InputStream |
getIn() |
protected InputStream |
getInputStream(File f,
long offset)
Convenience method for constructors.
|
protected Logger |
getLogger() |
protected static org.apache.commons.cli.Options |
getOptions() |
String |
getReaderIdentifier() |
String |
getStrippedFileName() |
static String |
getStrippedFileName(String name,
String dotFileExtension) |
protected static boolean |
getTrueOrFalse(String value) |
String |
getVersion() |
protected abstract void |
gotoEOR(ArchiveRecord record)
Skip over any trailing new lines at end of the record so we're lined up
ready to read the next.
|
protected void |
initialize(String i)
Convenience method used by subclass constructors.
|
boolean |
isCompressed() |
boolean |
isDigest() |
boolean |
isStrict() |
boolean |
isValid()
Test Archive file is valid.
|
Iterator<ArchiveRecord> |
iterator()
Returns an ArchiveRecord iterator.
|
void |
logStdErr(Level level,
String message)
Log on stderr.
|
protected boolean |
output(String format) |
protected static void |
outputRecord(ArchiveReader r,
String format)
Output passed record using passed format specifier.
|
boolean |
outputRecord(String format)
Output passed record using passed format specifier.
|
protected static long |
positionForRecord(InputStream in) |
protected void |
setCompressed(boolean compressed) |
void |
setDigest(boolean d) |
protected void |
setIn(InputStream in) |
protected void |
setReaderIdentifier(String i) |
void |
setStrict(boolean s) |
protected void |
setVersion(String version) |
protected static String |
stripExtension(String name,
String ext) |
List<ArchiveRecordHeader> |
validate()
Validate the Archive file.
|
List<ArchiveRecordHeader> |
validate(int numRecords)
Validate the Archive file.
|
protected InputStream in
Set in constructor. Should support at least 1 byte mark/reset. Make it protected so subclasses have access.
public static final int MAX_ALLOWED_RECOVERABLES
protected void initialize(String i)
i - Identifier for Archive file this reader goes against.protected InputStream getInputStream(File f, long offset) throws IOException
f - File to read.offset - Offset at which to start reading.IOException - If failed open or fail to get a memory
mapped byte buffer on file.public boolean isCompressed()
public ArchiveRecord get(long offset) throws IOException
offset.offset - Byte index into file at which a record starts.IOExceptionpublic ArchiveRecord get() throws IOException
IOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected void cleanupCurrentRecord()
throws IOException
IOExceptionprotected abstract ArchiveRecord createArchiveRecord(InputStream is, long offset) throws IOException
offset into
is.is - Stream to read Record from.offset - Offset to find Record at.IOExceptionprotected abstract void gotoEOR(ArchiveRecord record) throws IOException
record - IOExceptionpublic abstract String getFileExtension()
public abstract String getDotFileExtension()
public String getVersion()
public List<ArchiveRecordHeader> validate() throws IOException
Assumes the stream is at the start of the file.
IOExceptionpublic List<ArchiveRecordHeader> validate(int numRecords) throws IOException
We start validation from wherever we are in the stream.
numRecords - Number of records expected. Pass -1 if number is
unknown.IOExceptionpublic boolean isValid()
public boolean isStrict()
public void setStrict(boolean s)
s - The strict to set.public void setDigest(boolean d)
d - True if we're to digest.public boolean isDigest()
protected Logger getLogger()
public Iterator<ArchiveRecord> iterator()
strict is not set, this will usually succeed.iterator in interface Iterable<ArchiveRecord>protected void setCompressed(boolean compressed)
protected ArchiveRecord getCurrentRecord()
get()protected ArchiveRecord currentRecord(ArchiveRecord r)
protected InputStream getIn()
protected void setIn(InputStream in)
protected void setVersion(String version)
public String getReaderIdentifier()
protected void setReaderIdentifier(String i)
public void logStdErr(Level level, String message)
level - Level to log message at.message - Message to log.protected static long positionForRecord(InputStream in)
public String getFileName()
public String getStrippedFileName()
public static String getStrippedFileName(String name, String dotFileExtension)
name - Name of ARCFile.dotFileExtension - '.arc' or '.warc', etc.protected static boolean getTrueOrFalse(String value)
value - Value to test.protected boolean output(String format) throws IOException, ParseException
format - Format to use outputting.IOExceptionParseExceptionprotected void cdxOutput(boolean toFile)
throws IOException
IOExceptionpublic boolean outputRecord(String format) throws IOException
format - What format to use outputting.IOExceptionpublic abstract void dump(boolean compress)
throws IOException,
ParseException
compress - True if dumped output is compressed.IOExceptionParseExceptionpublic abstract ArchiveReader getDeleteFileOnCloseReader(File f)
protected static void outputRecord(ArchiveReader r, String format) throws IOException
r - ARCReader instance to output.format - What format to use outputting.IOExceptionprotected static org.apache.commons.cli.Options getOptions()
Copyright © 2015 The International Internet Preservation Consortium. All Rights Reserved.