dk.netarkivet.common.utils.arc
Class ARCUtils

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

public class ARCUtils
extends java.lang.Object

Various utilities that do stuff that ARCWriter does not provide. Also includes method for converting an ARCRecord to a byte array. TODO: Turn this into a wrapper around ARCWriter instead.


Field Summary
static java.lang.String RESPONSETEXT
          Extra ARC Record metadata
 
Constructor Summary
ARCUtils()
           
 
Method Summary
static org.archive.io.arc.ARCWriter createARCWriter(java.io.File newFile)
          Create new ARCWriter, writing to arcfile newFile.
static java.util.Map<java.lang.String,java.lang.Object> getHeadersFromARCFile(java.io.InputStream in, java.lang.Long offset)
          TODO: write unit test
static org.archive.io.arc.ARCWriter getToolsARCWriter(java.io.PrintStream stream, java.io.File destinationArcfile)
          Return an ARCWriter suitable for the tools ArcMerge and ArcWrap.
static void insertARCFile(java.io.File arcFile, org.archive.io.arc.ARCWriter aw)
          Insert the contents of an ARC file (skipping an optional initial filedesc: header) in another ARCfile.
static byte[] readARCRecord(org.archive.io.arc.ARCRecord in)
          Read the contents of an ARC record into a byte array.
static void writeFileToARC(org.archive.io.arc.ARCWriter aw, java.io.File file, java.lang.String uri, java.lang.String mime)
          Write a file to an ARC file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESPONSETEXT

public static final java.lang.String RESPONSETEXT
Extra ARC Record metadata

See Also:
Constant Field Values
Constructor Detail

ARCUtils

public ARCUtils()
Method Detail

insertARCFile

public static void insertARCFile(java.io.File arcFile,
                                 org.archive.io.arc.ARCWriter aw)
Insert the contents of an ARC file (skipping an optional initial filedesc: header) in another ARCfile.

Parameters:
arcFile - An ARC file to read.
aw - A place to write the arc records
Throws:
IOFailure - if there are problems reading the file.

createARCWriter

public static org.archive.io.arc.ARCWriter createARCWriter(java.io.File newFile)
Create new ARCWriter, writing to arcfile newFile.

Parameters:
newFile - the ARCfile, that the ARCWriter writes to.
Returns:
new ARCWriter, writing to arcfile newFile.

writeFileToARC

public static void writeFileToARC(org.archive.io.arc.ARCWriter aw,
                                  java.io.File file,
                                  java.lang.String uri,
                                  java.lang.String mime)
Write a file to an ARC file. The writing is done by an existing ARCWriter. An ARCRecord will be added, which contains a header and the contents of the file. The date of the record written will be set to the lastModified value of the file being written.

Parameters:
aw - The ARCWriter doing the writing
file - The file we want to write to the ARC file
uri - The uri for the ARCRecord being written
mime - The mimetype for the ARCRecord being written
Throws:
ArgumentNotValid - if any arguments aw and file are null and arguments uri and mime are null or empty.

getToolsARCWriter

public static org.archive.io.arc.ARCWriter getToolsARCWriter(java.io.PrintStream stream,
                                                             java.io.File destinationArcfile)
                                                      throws java.io.IOException
Return an ARCWriter suitable for the tools ArcMerge and ArcWrap.

Parameters:
stream - the given PrintStream.
destinationArcfile - the given destination ARC file.
Returns:
ARCWriter to be used by tools ArcMerge and ArcWrap
Throws:
java.io.IOException - redirect from ARCWriter constructure

readARCRecord

public static byte[] readARCRecord(org.archive.io.arc.ARCRecord in)
                            throws java.io.IOException
Read the contents of an ARC record into a byte array.

Parameters:
in - An ARC record to read from. After reading, the ARC Record will no longer have its own data available for reading.
Returns:
A byte array containing the contents of the ARC record. Note that the size of this may be different from the size given in the ARC record metadata.
Throws:
java.io.IOException - If there is an error reading the data, or if the record is longer than Integer.MAX_VALUE (since we can't make bigger arrays).

getHeadersFromARCFile

public static java.util.Map<java.lang.String,java.lang.Object> getHeadersFromARCFile(java.io.InputStream in,
                                                                                     java.lang.Long offset)
                                                                              throws java.io.IOException
TODO: write unit test

Parameters:
in - pointing at start of ARC record.
offset - into ARC file.
Returns:
pairwise headers.
Throws:
java.io.IOException - if fails to read ARC files or ARC files isn't valid.