ariba.util.core
Class FileComponentChecksum

java.lang.Object
  extended by ariba.util.core.ComponentChecksum
      extended by ariba.util.core.FileComponentChecksum
All Implemented Interfaces:
java.io.Serializable

public class FileComponentChecksum
extends ComponentChecksum

This class extends the ComponentChecksum class to compute a checksum for files and directories. The checksum used is Adler32. Adler32 is generally considedered as good as CRC32, and is twice as fast. In addition to the implmentation of getChecksum, several methods for adding files and directories to the checksum are included. The FileComponentChecksum object is not synchronized, and uses a object that is not thread safe, viz. the Checksum.

See Also:
Serialized Form

Constructor Summary
FileComponentChecksum(java.lang.String name)
           
 
Method Summary
 void addDirectory(java.io.File dir)
          Add all the files in the specified directory.
 void addDirectory(java.lang.String name)
          Add directory specified by string name
 void addDirectoryDeep(java.io.File dir)
          Add all the files in the specified directory.
 void addDirectoryDeep(java.lang.String name)
          Add directory specified by string name, and recurse to all subdirectories.
 void addFile(java.io.File f)
          Add the specified File to the checksum.
 void addFile(java.lang.String name)
          Add the file specified by the string name
 void addFileList(java.util.List v)
          Adds all of the files in the given List.
 void addFileList(java.util.List v, boolean sortFirst)
          Adds all of the files in the given List.
 byte[] getChecksum()
          Return the accumulated checksum as a byte array (big endian).
 
Methods inherited from class ariba.util.core.ComponentChecksum
compareChecksum, getName, makeListOfBytes, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileComponentChecksum

public FileComponentChecksum(java.lang.String name)
Method Detail

getChecksum

public byte[] getChecksum()
Return the accumulated checksum as a byte array (big endian).

Specified by:
getChecksum in class ComponentChecksum
Returns:
The checksum accumulated so far

addFile

public void addFile(java.io.File f)
             throws ComponentChecksumException
Add the specified File to the checksum. If the File is not a normal file, throw an exception. Use addDirectory or addDirectoryDeep for directories. If there are any IO errors, log them, then throw an exception.

Parameters:
f - File whose name and contents we want to add to the checksum
Throws:
ComponentChecksumException - The file was not a normal file, the file did not exist, or there was some other IO error.

addFile

public void addFile(java.lang.String name)
             throws ComponentChecksumException
Add the file specified by the string name

Parameters:
name - String name of the file to add
Throws:
ComponentChecksumException

addFileList

public void addFileList(java.util.List v)
                 throws ComponentChecksumException
Adds all of the files in the given List. The files are represented as filename Strings. They are added to the checksum in the same order as the given List.

Parameters:
v - List containing the filenames
Throws:
ComponentChecksumException - The file was not a normal file, the file did not exist, or there was some other IO error.

addFileList

public void addFileList(java.util.List v,
                        boolean sortFirst)
                 throws ComponentChecksumException
Adds all of the files in the given List. The files are represented as filename Strings. Optionally sorts the filenames before adding the files to the checksum.

Parameters:
v - List containing the filenames
sortFirst - if true, sorts the filenames before adding them to this checksum (the checksum value is dependent on the order in which files are added)
Throws:
ComponentChecksumException - The file was not a normal file, the file did not exist, or there was some other IO error.

addDirectory

public void addDirectory(java.io.File dir)
                  throws ComponentChecksumException
Add all the files in the specified directory. This call stays at this level, and does not go any deeper. Use addDirectoryDeep if you want to recurse through all levels.

Parameters:
dir - File for the directory
Throws:
ComponentChecksumException - The File specified is not a directory or did not exist, or some other IO exception occurred.

addDirectory

public void addDirectory(java.lang.String name)
                  throws ComponentChecksumException
Add directory specified by string name

Parameters:
name - name of the directory to add
Throws:
ComponentChecksumException - the directory does not exit, is not a directory, or there was a file IO error while processing

addDirectoryDeep

public void addDirectoryDeep(java.io.File dir)
                      throws ComponentChecksumException
Add all the files in the specified directory. This call recurses down to each subdirectory.

Parameters:
dir - File for the directory
Throws:
ComponentChecksumException - The File specified is not a directory or did not exist, or some other IO exception occurred.

addDirectoryDeep

public void addDirectoryDeep(java.lang.String name)
                      throws ComponentChecksumException
Add directory specified by string name, and recurse to all subdirectories.

Parameters:
name - name of the directory to add
Throws:
ComponentChecksumException - the directory does not exit, is not a directory, or there was a file IO error while processing


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.