Package dk.netarkivet.common.utils.batch
Class ChecksumJob
- java.lang.Object
-
- dk.netarkivet.common.utils.batch.FileBatchJob
-
- dk.netarkivet.common.utils.batch.ChecksumJob
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
TestChecksumJob
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
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
The log.static 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
Constructors Constructor Description ChecksumJob()
The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
finish(OutputStream os)
Finishing the job requires nothing particular.void
initialize(OutputStream os)
Initialization of a ChecksumJob: a new structure for storing files failed is created.static String
makeLine(String filename, String checksum)
Create a line in checksum job format from a filename and a checksum.static KeyValuePair<String,String>
parseLine(String line)
Parse a line of output into a key-value pair.boolean
processFile(File file, OutputStream os)
Generates MD5 checksum for file identified by 'file' and writes the checksum to the given OutputStream.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
-
-
-
-
Field Detail
-
log
protected static final transient org.slf4j.Logger log
The log.
-
STRING_FILENAME_SEPARATOR
public static final 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
-
-
Method Detail
-
initialize
public void initialize(OutputStream os)
Initialization of a ChecksumJob: a new structure for storing files failed is created.- Specified by:
initialize
in classFileBatchJob
- Parameters:
os
- The output stream where the output data is written.- See Also:
FileBatchJob.initialize(OutputStream)
-
processFile
public boolean processFile(File file, 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 classFileBatchJob
- 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(OutputStream os)
Finishing the job requires nothing particular.- Specified by:
finish
in classFileBatchJob
- Parameters:
os
- The output stream where the output data is written.- See Also:
FileBatchJob.finish(OutputStream)
-
makeLine
public static String makeLine(String filename, 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<String,String> parseLine(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 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.
-
-