dk.netarkivet.common.utils.batch
Class ChecksumJob

java.lang.Object
  extended by dk.netarkivet.common.utils.batch.FileBatchJob
      extended by dk.netarkivet.common.utils.batch.ChecksumJob
All Implemented Interfaces:
java.io.Serializable

public class ChecksumJob
extends FileBatchJob

Class responsible for checksumming a list of files.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class dk.netarkivet.common.utils.batch.FileBatchJob
FileBatchJob.ExceptionOccurrence
 
Field Summary
protected  org.apache.commons.logging.Log log
          The log.
static java.lang.String STRING_FILENAME_SEPARATOR
          Characters used for separating a file identifier from the checksum in the output from a checksum job.
 
Fields inherited from class dk.netarkivet.common.utils.batch.FileBatchJob
batchJobTimeout, exceptions, filesFailed, noOfFilesProcessed
 
Constructor Summary
ChecksumJob()
          The constructor.
 
Method Summary
 void finish(java.io.OutputStream os)
          Finishing the job requires nothing particular.
 void initialize(java.io.OutputStream os)
          Initialization of a ChecksumJob: a new structure for storing files failed is created.
static java.lang.String makeLine(java.lang.String filename, java.lang.String checksum)
          Create a line in checksum job format from a filename and a checksum.
static KeyValuePair<java.lang.String,java.lang.String> parseLine(java.lang.String line)
          Parse a line of output into a key-value pair.
 boolean processFile(java.io.File file, java.io.OutputStream os)
          Generates MD5 checksum for file identified by 'file' and writes the checksum to the given OutputStream.
 java.lang.String toString()
          Write a human-readily description of this ChecksumJob object.
 
Methods inherited from class dk.netarkivet.common.utils.batch.FileBatchJob
addException, addFinishException, addInitializeException, getBatchJobTimeout, getExceptions, getFilenamePattern, getFilesFailed, getNoOfFilesProcessed, maxExceptionsReached, postProcess, processOnlyFileNamed, processOnlyFilesMatching, processOnlyFilesMatching, processOnlyFilesNamed, setBatchJobTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected transient org.apache.commons.logging.Log log
The log.


STRING_FILENAME_SEPARATOR

public static final java.lang.String STRING_FILENAME_SEPARATOR
Characters used for separating a file identifier from the checksum in the output from a checksum job.

See Also:
Constant Field Values
Constructor Detail

ChecksumJob

public ChecksumJob()
The constructor.

Method Detail

initialize

public void initialize(java.io.OutputStream os)
Initialization of a ChecksumJob: a new structure for storing files failed is created.

Specified by:
initialize in class FileBatchJob
Parameters:
os - The output stream where the output data is written.
See Also:
FileBatchJob.initialize(OutputStream)

processFile

public boolean processFile(java.io.File file,
                           java.io.OutputStream os)
Generates MD5 checksum for file identified by 'file' and writes the checksum to the given OutputStream. Errors during checksumming are logged and files on which checksumming fails are stored in filesFailed.

Specified by:
processFile in class FileBatchJob
Parameters:
file - The file to process.
os - The outputStream to write the result to
Returns:
false, if errors occurred while processing the file
See Also:
FileBatchJob.processFile(File, OutputStream)

finish

public void finish(java.io.OutputStream os)
Finishing the job requires nothing particular.

Specified by:
finish in class FileBatchJob
Parameters:
os - The output stream where the output data is written.
See Also:
FileBatchJob.finish(OutputStream)

makeLine

public static java.lang.String makeLine(java.lang.String filename,
                                        java.lang.String checksum)
Create a line in checksum job format from a filename and a checksum.

Parameters:
filename - A filename (no path)
checksum - An MD5 checksum
Returns:
A string of the correct format for a checksum job output.

parseLine

public static KeyValuePair<java.lang.String,java.lang.String> parseLine(java.lang.String line)
                                                                 throws ArgumentNotValid
Parse a line of output into a key-value pair.

Parameters:
line - The line to parse, of the form filename##checksum
Returns:
The filename->checksum mapping.
Throws:
ArgumentNotValid - if the line is not on the correct form.

toString

public java.lang.String toString()
Write a human-readily description of this ChecksumJob object. Writes out the name of the ChecksumJob, the number of files processed, and the number of files that failed during processing.

Overrides:
toString in class java.lang.Object
Returns:
a human-readily description of this ChecksumJob object