jonelo.jacksum.algorithm

Class AbstractChecksum

Implemented Interfaces:
Checksum

public abstract class AbstractChecksum
extends java.lang.Object
implements Checksum

An abstract class that is actually the parent of all algorithms.

Field Summary

static String
BASE16
static String
BASE32
static String
BASE64
static String
BIN
static String
BUBBLEBABBLE
static int
BUFFERSIZE
static String
DEC
static String
HEX
static String
HEX_UPPERCASE
static String
OCT
protected String
encoding
protected String
filename
protected int
group
protected char
groupChar
protected long
length
protected String
name
protected String
separator
protected long
timestamp
protected String
timestampFormat
protected Format
timestampFormatter
protected long
value

Constructor Summary

AbstractChecksum()
Creates an AbstractChecksum.

Method Summary

boolean
equals(Object anObject)
Returns true only if the specified checksum is equal to this object.
void
firstFormat(StringBuffer format)
String
format(String format)
byte[]
getByteArray()
Returns the result of the computation as byte array.
String
getEncoding()
Gets the encoding of the checksum.
String
getFilename()
Gets the filename.
String
getFormattedValue()
Returns the checksum formatted.
int
getGroup()
Gets the number of groups (make sense only if encoding is HEX or HEXUP).
char
getGroupChar()
Gets the group char (works only if encoding is HEX or HEXUP).
String
getHexValue()
Deprecated. As of Jacksum version 1.6 replaced by getByteArray().
long
getLength()
Returns the length of the processed bytes.
String
getName()
String
getSeparator()
Gets the separator.
long
getTimestamp()
String
getTimestampFormat()
Gets the format of the timestamp.
String
getTimestampFormatted()
Gets the timestamp, formatted.
long
getValue()
Returns the value of the checksum.
int
hashCode()
boolean
isGroupWanted()
Returns true if groups are wanted (make sense only if encoding is HEX or HEXUP).
boolean
isTimestampWanted()
Determines if a timestamp is wanted.
long
readFile(String filename)
Reads a file and calculates the checksum from it.
long
readFile(String filename, boolean reset)
Reads a file and calculates the checksum from it.
void
reset()
Resets the checksum to its initial value for further use.
void
setEncoding(String encoding)
Sets the encoding of the checksum.
void
setFilename(String filename)
Sets the filename.
void
setGroup(int group)
Sets the number of groups (make sense only if encoding is HEX or HEXUP).
void
setGroupChar(char groupChar)
Sets the group char (make sense only if encoding is HEX or HEXUP).
void
setGrouping(int group, char groupChar)
Sets the number of groups and the group char.
void
setHex(boolean hex)
Deprecated. As of Jacksum version 1.6 replaced by setEncoding().
void
setName(String name)
Set the name of the algorithm
void
setSeparator(String separator)
Sets the separator for the tokens.
void
setTimestamp(String filename)
Sets the timestamp.
void
setTimestampFormat(String timestampFormat)
Sets the timestampFormat to force a timestamp output
void
setUpperCase(boolean uppercase)
Deprecated. As of Jacksum version 1.6 replaced by setEncoding().
String
toString()
The toString() method.
void
update(byte b)
Updates the checksum with the specified byte.
void
update(byte[] bytes)
Updates the current checksum with the specified array of bytes.
void
update(byte[] bytes, int offset, int length)
Updates the current checksum with the specified array of bytes.
void
update(int b)
Updates the checksum with the specified byte.

Field Details

BASE16

public static final String BASE16

BASE32

public static final String BASE32

BASE64

public static final String BASE64

BIN

public static final String BIN

BUBBLEBABBLE

public static final String BUBBLEBABBLE

BUFFERSIZE

public static final int BUFFERSIZE
Field Value:
8192

DEC

public static final String DEC

HEX

public static final String HEX

HEX_UPPERCASE

public static final String HEX_UPPERCASE

OCT

public static final String OCT

encoding

protected String encoding

filename

protected String filename

group

protected int group

groupChar

protected char groupChar

length

protected long length

name

protected String name

separator

protected String separator

timestamp

protected long timestamp

timestampFormat

protected String timestampFormat

timestampFormatter

protected Format timestampFormatter

value

protected long value

Constructor Details

AbstractChecksum

public AbstractChecksum()
Creates an AbstractChecksum.

Method Details

equals

public boolean equals(Object anObject)
Returns true only if the specified checksum is equal to this object.

firstFormat

public void firstFormat(StringBuffer format)

format

public String format(String format)

getByteArray

public byte[] getByteArray()
Returns the result of the computation as byte array.
Since:
Jacksum 1.6

getEncoding

public String getEncoding()
Gets the encoding of the checksum.

getFilename

public String getFilename()
Gets the filename.

getFormattedValue

public String getFormattedValue()
Returns the checksum formatted.
Since:
Jacksum 1.6

getGroup

public int getGroup()
Gets the number of groups (make sense only if encoding is HEX or HEXUP).

getGroupChar

public char getGroupChar()
Gets the group char (works only if encoding is HEX or HEXUP).

getHexValue

public String getHexValue()

Deprecated. As of Jacksum version 1.6 replaced by getByteArray().

Gets the format of the checksum as hex.

getLength

public long getLength()
Returns the length of the processed bytes.

getName

public String getName()

getSeparator

public String getSeparator()
Gets the separator.

getTimestamp

public long getTimestamp()

getTimestampFormat

public String getTimestampFormat()
Gets the format of the timestamp.

getTimestampFormatted

public String getTimestampFormatted()
Gets the timestamp, formatted.

getValue

public long getValue()
Returns the value of the checksum.

hashCode

public int hashCode()

isGroupWanted

public boolean isGroupWanted()
Returns true if groups are wanted (make sense only if encoding is HEX or HEXUP).

isTimestampWanted

public boolean isTimestampWanted()
Determines if a timestamp is wanted.

readFile

public long readFile(String filename)
            throws IOException
Reads a file and calculates the checksum from it.
Parameters:
filename - - the file which should be read

readFile

public long readFile(String filename,
                     boolean reset)
            throws IOException
Reads a file and calculates the checksum from it.
Parameters:
filename - the filename which should be read
reset - if reset is true, reset() will be launched before the checksum gets updated
See Also:
reset()

reset

public void reset()
Resets the checksum to its initial value for further use.

setEncoding

public void setEncoding(String encoding)
            throws EncodingException
Sets the encoding of the checksum.
Parameters:
encoding - the encoding of the checksum.
Since:
1.6

setFilename

public void setFilename(String filename)
Sets the filename.
Parameters:
filename - the filename.

setGroup

public void setGroup(int group)
Sets the number of groups (make sense only if encoding is HEX or HEXUP).

setGroupChar

public void setGroupChar(char groupChar)
Sets the group char (make sense only if encoding is HEX or HEXUP).

setGrouping

public void setGrouping(int group,
                        char groupChar)
Sets the number of groups and the group char. (make sense only if encoding is HEX or HEXUP).

setHex

public void setHex(boolean hex)

Deprecated. As of Jacksum version 1.6 replaced by setEncoding().

Sets the format of the checksum as hex or default.

setName

public void setName(String name)
Set the name of the algorithm
Parameters:
name - the name of the algorithm

setSeparator

public void setSeparator(String separator)
Sets the separator for the tokens.

setTimestamp

public void setTimestamp(String filename)
Sets the timestamp.
Parameters:
filename - the file from which the timestamp should be gathered.

setTimestampFormat

public void setTimestampFormat(String timestampFormat)
Sets the timestampFormat to force a timestamp output
Parameters:
timestampFormat - the format of the timestamp.

setUpperCase

public void setUpperCase(boolean uppercase)

Deprecated. As of Jacksum version 1.6 replaced by setEncoding().

Sets the format of the checksum as uppercase hex or lowercase hex.

toString

public String toString()
The toString() method.

update

public void update(byte b)
Updates the checksum with the specified byte.

update

public void update(byte[] bytes)
Updates the current checksum with the specified array of bytes.

update

public void update(byte[] bytes,
                   int offset,
                   int length)
Updates the current checksum with the specified array of bytes.
Parameters:
bytes - the byte array to update the checksum with
offset - the start offset of the data
length - the number of bytes to use for the update

update

public void update(int b)
Updates the checksum with the specified byte.