dk.netarkivet.common.utils.arc
Class ShareableARCRecord

java.lang.Object
  extended by dk.netarkivet.common.utils.arc.ShareableARCRecord

public class ShareableARCRecord
extends java.lang.Object

Class for reading a record in an ARC file. This class wraps around an org.archive.io.arc.ARCRecord. The main functionality added is that this class can return InputStreams to the record object at will, allowing multiple consumers to share the object. A ShareableARCRecord can also tell which file the current record was found in (useful for indexing).


Constructor Summary
ShareableARCRecord(org.archive.io.arc.ARCRecord record, java.io.File fromFile)
          Creates a ShareableARCRecord from an ARCRecord and the File in which the ARCRecord was found.
 
Method Summary
 org.archive.io.arc.ARCRecord getARCRecord()
          Returns the ARC record around which the ShareableARCRecord is based.
 ReadOnlyByteArray getDataReadOnly()
          Reads all the data in the ARCRecord's InputStream.
 java.io.File getFile()
          Returns the file that this ARC record comes from.
 org.archive.io.arc.ARCRecordMetaData getMetaData()
          Returns the metadata of this ARC record.
 java.io.InputStream getObjectAsInputStream()
          Allows the caller to read the record object itself.
 byte[] readAll()
          Reads all the data in the ARCRecord's InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShareableARCRecord

public ShareableARCRecord(org.archive.io.arc.ARCRecord record,
                          java.io.File fromFile)
Creates a ShareableARCRecord from an ARCRecord and the File in which the ARCRecord was found.

Parameters:
record - - an ARCRecord that the return object should wrap around. Note that this object does not close the record, but holds on to the record. The record can be closed after readAll(), getDataReadOnly() or getObjectAsInputStream() has been called.
fromFile - - the ARC file in which the ARCRecord was found.
Method Detail

getFile

public java.io.File getFile()
Returns the file that this ARC record comes from.

Returns:
the file that this ARC record comes from.

getMetaData

public org.archive.io.arc.ARCRecordMetaData getMetaData()
Returns the metadata of this ARC record.

Returns:
the metadata belonging to this ARC record.

readAll

public byte[] readAll()
               throws java.io.IOException
Reads all the data in the ARCRecord's InputStream. A "fresh copy" of the data is made, so the caller is free to manipulate the returned array at will.

Returns:
an array of bytes read from the ARC file. This may be quite large.
Throws:
java.io.IOException - if reading fails

getDataReadOnly

public ReadOnlyByteArray getDataReadOnly()
                                  throws java.io.IOException
Reads all the data in the ARCRecord's InputStream. The data is not copied, but the call ensures that the data has been read into memory.

Returns:
a read-only array of bytes read from the ARC file. This may be quite large.
Throws:
java.io.IOException - if reading fails

getObjectAsInputStream

public java.io.InputStream getObjectAsInputStream()
                                           throws java.io.IOException
Allows the caller to read the record object itself. Multiple calls to this method return different InputStreams, so that many calling objects may read without interference.

Returns:
an InputStream representing the object in the ARCRecord.
Throws:
java.io.IOException - if there are problems reading the object

getARCRecord

public org.archive.io.arc.ARCRecord getARCRecord()
Returns the ARC record around which the ShareableARCRecord is based. Note that if record data are read from the ARCRecord, the ShareableARCRecord is no longer able to fulfill its contracts, as data will be gone from the inputstream.

Returns:
the ARCRecord for this ShareableARC record.