com.tffenterprises.io
Class DataOutputChecksum

java.lang.Object
  extended by com.tffenterprises.io.DataOutputChecksum
All Implemented Interfaces:
java.io.DataOutput, java.util.zip.Checksum

public class DataOutputChecksum
extends java.lang.Object
implements java.io.DataOutput, java.util.zip.Checksum

DataOutputChecksum is a utility when using implementors of the java.util.zip.Checksum interface. This class acts as a wrapper for a Checksum object, adding to it the methods declared by the java.io.DataOutput interface.

Version:
1.0d1 $Date: 2002/10/12 19:59:22 $
Author:
Guillaume Lessard

Field Summary
private  byte[] buf
          private buffer to assist with the more complicated DataOutput methods.
private  java.util.zip.Checksum cs
          The encapsulated checksum object.
 
Constructor Summary
private DataOutputChecksum()
          A private constructor.
  DataOutputChecksum(java.util.zip.Checksum checksum)
          Creates a DataOutputChecksum that encapsulate a Checksum implementor.
 
Method Summary
 java.util.zip.Checksum getChecksum()
          Returns the encapsulated checksum object.
 long getValue()
          Returns the current checksum value.
 void reset()
          Resets the checksum to its initial value.
 void update(byte[] b)
          Updates the checksum with the specified byte array.
 void update(byte[] b, int off, int len)
          Updates the checksum with len bytes from the specified byte array, starting from offset off
 void update(int b)
          Updates the checksum with a single byte b
 void write(byte[] b)
          Writes an array.
 void write(byte[] b, int off, int len)
          Writes a subarray from an offset.
 void write(int b)
          Writes a byte.
 void writeBoolean(boolean bool)
          Writes a boolean value to this output stream.
 void writeByte(int b)
          Writes a byte value to this output stream.
 void writeBytes(java.lang.String s)
          Writes the low-order-byte values of the given String parameter's chars, effectively writing the characters as ISO-8859-1 encoding.
 void writeChar(int c)
          Writes a char value to this output stream.
 void writeChars(java.lang.String s)
          Writes a String as a sequence of chars (2-byte values).
 void writeDouble(double d)
          Writes a double value to this output stream.
 void writeFloat(float f)
          Writes a float value to this output stream.
 void writeInt(int i)
          Writes an int value to this output stream.
 void writeLong(long l)
          Writes a long value to this output stream.
 void writeShort(int s)
          Writes a short value to this output stream.
 void writeUTF(java.lang.String s)
          Writes a String encoded as UTF-8.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

private byte[] buf
private buffer to assist with the more complicated DataOutput methods.


cs

private java.util.zip.Checksum cs
The encapsulated checksum object.

Constructor Detail

DataOutputChecksum

private DataOutputChecksum()
A private constructor. Since this object needs an underlying Checksum, the default constructor can't be used.


DataOutputChecksum

public DataOutputChecksum(java.util.zip.Checksum checksum)
Creates a DataOutputChecksum that encapsulate a Checksum implementor.

Parameters:
checksum - the Checksum object to encapsulate.
Method Detail

update

public final void update(byte[] b)
Updates the checksum with the specified byte array.

This is equivalent to using update(b, 0, b.length).

Parameters:
b - the data

update

public void update(byte[] b,
                   int off,
                   int len)
Updates the checksum with len bytes from the specified byte array, starting from offset off

Specified by:
update in interface java.util.zip.Checksum
Parameters:
b - the data
off - the offset at which to start reading from the array
len - the number of bytes to read from the array

update

public void update(int b)
Updates the checksum with a single byte b

Specified by:
update in interface java.util.zip.Checksum
Parameters:
b - the byte.

getValue

public long getValue()
Returns the current checksum value.

Specified by:
getValue in interface java.util.zip.Checksum
Returns:
the current checksum value.

reset

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

Specified by:
reset in interface java.util.zip.Checksum

write

public void write(int b)
Writes a byte.

Specified by:
write in interface java.io.DataOutput
Parameters:
b - the byte.

write

public void write(byte[] b)
Writes an array.

Specified by:
write in interface java.io.DataOutput
Parameters:
b - the bytes.

write

public void write(byte[] b,
                  int off,
                  int len)
Writes a subarray from an offset.

Specified by:
write in interface java.io.DataOutput
Parameters:
b - the bytes
off - the offset
len - the length

writeBoolean

public void writeBoolean(boolean bool)
Writes a boolean value to this output stream.

Specified by:
writeBoolean in interface java.io.DataOutput
Parameters:
bool - the boolean value to be written out.

writeByte

public void writeByte(int b)
Writes a byte value to this output stream.

Specified by:
writeByte in interface java.io.DataOutput
Parameters:
b - the byte value to be written out.

writeShort

public void writeShort(int s)
Writes a short value to this output stream.

Specified by:
writeShort in interface java.io.DataOutput
Parameters:
s - the short value to be written out.

writeChar

public void writeChar(int c)
Writes a char value to this output stream.

Specified by:
writeChar in interface java.io.DataOutput
Parameters:
c - the char value to be written out.

writeInt

public void writeInt(int i)
Writes an int value to this output stream.

Specified by:
writeInt in interface java.io.DataOutput
Parameters:
i - the int value to be written out.

writeLong

public void writeLong(long l)
Writes a long value to this output stream.

Specified by:
writeLong in interface java.io.DataOutput
Parameters:
l - the long value to be written out.

writeFloat

public void writeFloat(float f)
Writes a float value to this output stream.

Specified by:
writeFloat in interface java.io.DataOutput
Parameters:
f - the float value to be written out.

writeDouble

public void writeDouble(double d)
Writes a double value to this output stream.

Specified by:
writeDouble in interface java.io.DataOutput
Parameters:
d - the double value to be written out.

writeBytes

public void writeBytes(java.lang.String s)
Writes the low-order-byte values of the given String parameter's chars, effectively writing the characters as ISO-8859-1 encoding.

Specified by:
writeBytes in interface java.io.DataOutput
Parameters:
s - the String to be written out as ISO-8859-1.

writeChars

public void writeChars(java.lang.String s)
Writes a String as a sequence of chars (2-byte values).

Specified by:
writeChars in interface java.io.DataOutput
Parameters:
s - the String to be written out to the stream.

writeUTF

public void writeUTF(java.lang.String s)
Writes a String encoded as UTF-8. This method differs from the DataOutput interface in that it does not verify the length of the UTF-8 data, nor does it write the length of the data to the embedded Checksum object.

Specified by:
writeUTF in interface java.io.DataOutput
Parameters:
s - the String to be written out to the stream as UTF-8.

getChecksum

public java.util.zip.Checksum getChecksum()
Returns the encapsulated checksum object.

Returns:
the encapsulated checksum object.