totalcross.io
Class CRC32Stream

totalcross.lang.Object
  extended by totalcross.io.Stream
      extended by totalcross.io.CRC32Stream

public class CRC32Stream
extends Stream

Computes CRC32 data checksum of a stream. The actual CRC32 algorithm is described in RFC 1952 (GZIP file format specification version 4.3). Can be used to get the CRC32 over a stream if used with input/output streams.


Field Summary
static int[] crcTable
          The fast CRC table.
 
Fields inherited from class totalcross.io.Stream
skipBuffer
 
Constructor Summary
CRC32Stream(Stream s)
           
 
Method Summary
 void close()
          This method does nothing.
 long getValue()
          Returns the CRC32 data checksum computed so far.
 int readBytes(byte[] buf, int start, int count)
          Computes the checksum for the bytes read from the attached stream.
 void reset()
          Resets the CRC32 data checksum so a new CRC32 can be computed.
 void update(byte[] buf, int off, int len)
          Updates the CRC32 with the values of the given buffer.
 int writeBytes(byte[] buf, int start, int count)
          Computes the checksum for the given bytes, then write them to the attached stream.
 
Methods inherited from class totalcross.io.Stream
skipBytes, writeBytes, writeBytes
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

crcTable

public static int[] crcTable
The fast CRC table. Computed once when the CRC32 class is loaded.

Constructor Detail

CRC32Stream

public CRC32Stream(Stream s)
Method Detail

getValue

public long getValue()
Returns the CRC32 data checksum computed so far. You can safely cast it to int, but then the value may be negative.

Returns:
an unsigned crc value in the int range.

reset

public void reset()
Resets the CRC32 data checksum so a new CRC32 can be computed.


close

public void close()
This method does nothing.


update

public void update(byte[] buf,
                   int off,
                   int len)
Updates the CRC32 with the values of the given buffer.


readBytes

public int readBytes(byte[] buf,
                     int start,
                     int count)
              throws IOException
Computes the checksum for the bytes read from the attached stream.

Specified by:
readBytes in class Stream
Parameters:
buf - the byte array to read data into
start - the start position in the array
count - the number of bytes to read
Returns:
The number of bytes read from the underlying stream.
Throws:
IOException

writeBytes

public int writeBytes(byte[] buf,
                      int start,
                      int count)
               throws IOException
Computes the checksum for the given bytes, then write them to the attached stream.

Specified by:
writeBytes in class Stream
Parameters:
buf - the byte array to write data from
start - the start position in the byte array
count - the number of bytes to write
Returns:
The number of bytes written to the underlying stream.
Throws:
IOException