Methods Summary |
---|
public java.lang.String | getValue(java.io.File file)Computes a value for a file content with the specified checksum algorithm.
initChecksum();
String rval = null;
try {
if (file.canRead()) {
checksum.reset();
FileInputStream fis = new FileInputStream(file);
CheckedInputStream check = new CheckedInputStream(fis, checksum);
BufferedInputStream in = new BufferedInputStream(check);
while (in.read() != -1) {
// Read the file
}
rval = Long.toString(check.getChecksum().getValue());
in.close();
}
} catch (Exception e) {
rval = null;
}
return rval;
|
public void | initChecksum()Initialize the checksum interface.
if (checksum != null) {
return;
}
if ("CRC".equalsIgnoreCase(algorithm)) {
checksum = new CRC32();
} else if ("ADLER".equalsIgnoreCase(algorithm)) {
checksum = new Adler32();
} else {
throw new BuildException(new NoSuchAlgorithmException());
}
|
public boolean | isValid()This algorithm supports only CRC and Adler.
return "CRC".equalsIgnoreCase(algorithm) || "ADLER".equalsIgnoreCase(algorithm);
|
public void | setAlgorithm(java.lang.String algorithm)Specifies the algorithm to be used to compute the checksum.
Defaults to "CRC". Other popular algorithms like "ADLER" may be used as well.
// ----- Algorithm-Configuration -----
this.algorithm = algorithm;
|
public java.lang.String | toString()Override Object.toString().
StringBuffer buf = new StringBuffer();
buf.append("<ChecksumAlgorithm:");
buf.append("algorithm=").append(algorithm);
buf.append(">");
return buf.toString();
|