Class ARCReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<ArchiveRecord>
- Direct Known Subclasses:
ARCReaderFactory.CompressedARCReader,ARCReaderFactory.UncompressedARCReader
This class knows how to parse an ARC file. Pass it a file path or an URL to an ARC. It can parse ARC Version 1 and 2.
Iterator returns ARCRecord
though Iterator.next() is returning
java.lang.Object. Cast the return.
Profiling java.io vs. memory-mapped ByteBufferInputStream shows the
latter slightly slower -- but not by much. TODO: Test more. Just
change ArchiveReader.getInputStream(File, long).
- Version:
- $Date$ $Revision$
- Author:
- stack
-
Nested Class Summary
Nested classes/interfaces inherited from class org.archive.io.ArchiveReader
ArchiveReader.ArchiveRecordIterator -
Field Summary
Fields inherited from class org.archive.io.ArchiveReader
in, MAX_ALLOWED_RECOVERABLES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ARCRecordcreateArchiveRecord(InputStream is, long offset) Create new arc record.static voidcreateCDXIndexFile(String urlOrPath) Generate a CDX index file for an ARC file.voiddump(boolean compress) Dump this file on STDOUTReturns version of this ARC file.protected voidgotoEOR(ArchiveRecord record) Skip over any trailing new lines at end of the record so we're lined up ready to read the next.protected booleanbooleanstatic voidCommand-line interface to ARCReader.protected booleanprotected static voidWrite out the arcfile.booleanoutputRecord(String format) Output passed record using passed format specifier.protected voidsetAlignedOnFirstRecord(boolean alignedOnFirstRecord) voidsetParseHttpHeaders(boolean parse) Methods inherited from class org.archive.io.ArchiveReader
cdxOutput, cleanupCurrentRecord, close, currentRecord, get, get, getCurrentRecord, getFileName, getIn, getInputStream, getLogger, getOptions, getReaderIdentifier, getStrippedFileName, getStrippedFileName, getTrueOrFalse, initialize, isCompressed, isDigest, isStrict, isValid, iterator, logStdErr, outputRecord, positionForRecord, setCompressed, setDigest, setIn, setReaderIdentifier, setStrict, setVersion, stripExtension, validate, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ARCReader
protected ARCReader()
-
-
Method Details
-
gotoEOR
Skip over any trailing new lines at end of the record so we're lined up ready to read the next.- Specified by:
gotoEORin classArchiveReader- Parameters:
record-- Throws:
IOException
-
createArchiveRecord
Create new arc record. Encapsulate housekeeping that has to do w/ creating a new record.Call this method at end of constructor to read in the arcfile header. Will be problems reading subsequent arc records if you don't since arcfile header has the list of metadata fields for all records that follow.
When parsing through ARCs writing out CDX info, we spend about 38% of CPU in here -- about 30% of which is in getTokenizedHeaderLine -- of which 16% is reading.
- Specified by:
createArchiveRecordin classArchiveReader- Parameters:
is- InputStream to use.offset- Absolute offset into arc file.- Returns:
- An arc record.
- Throws:
IOException
-
getVersion
Returns version of this ARC file. Usually read from first record of ARC. If we're reading without having first read the first record -- e.g. random access into middle of an ARC -- then version will not have been set. For now, we return a default, version 1.1. Later, if more than just one version of ARC, we could look at such as the meta line to see what version of ARC this is.- Overrides:
getVersionin classArchiveReader- Returns:
- Version of this ARC file.
-
isAlignedOnFirstRecord
protected boolean isAlignedOnFirstRecord() -
setAlignedOnFirstRecord
protected void setAlignedOnFirstRecord(boolean alignedOnFirstRecord) -
isParseHttpHeaders
public boolean isParseHttpHeaders()- Returns:
- Returns the parseHttpHeaders.
-
setParseHttpHeaders
public void setParseHttpHeaders(boolean parse) - Parameters:
parse- The parseHttpHeaders to set.
-
getFileExtension
- Specified by:
getFileExtensionin classArchiveReader
-
getDotFileExtension
- Specified by:
getDotFileExtensionin classArchiveReader
-
output
- Overrides:
outputin classArchiveReader- Parameters:
format- Format to use outputting.- Returns:
- True if handled.
- Throws:
IOExceptionParseException
-
outputRecord
Description copied from class:ArchiveReaderOutput passed record using passed format specifier.- Overrides:
outputRecordin classArchiveReader- Parameters:
format- What format to use outputting.- Returns:
- True if handled.
- Throws:
IOException
-
dump
Description copied from class:ArchiveReaderDump this file on STDOUT- Specified by:
dumpin classArchiveReader- Parameters:
compress- True if dumped output is compressed.- Throws:
IOExceptionParseException
-
getDeleteFileOnCloseReader
- Specified by:
getDeleteFileOnCloseReaderin classArchiveReader- Returns:
- an ArchiveReader that will delete a local file on close. Used when we bring Archive files local and need to clean up afterward.
-
output
Write out the arcfile.- Parameters:
reader-format- Format to use outputting.- Throws:
IOExceptionParseException
-
createCDXIndexFile
Generate a CDX index file for an ARC file.- Parameters:
urlOrPath- The ARC file to generate a CDX index for- Throws:
IOExceptionParseException
-
main
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException, ParseException Command-line interface to ARCReader. Here is the command-line interface:usage: java org.archive.io.arc.ARCReader [--offset=#] ARCFILE -h,--help Prints this message and exits. -o,--offset Outputs record at this offset into arc file.
See in
$HERITRIX_HOME/bin/arcreaderfor a script that'll take care of classpaths and the calling of ARCReader.Outputs using a pseudo-CDX format as described here: CDX Legent and here Example. Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. Hash is hard-coded straight SHA-1 hash of content.
- Parameters:
args- Command-line arguments.- Throws:
org.apache.commons.cli.ParseException- Failed parse of the command line.IOExceptionParseException
-