Package totalcross.io
Class CRC32Stream
- java.lang.Object
-
- totalcross.io.Stream
-
- totalcross.io.CRC32Stream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
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
Fields Modifier and Type Field Description static int[]crcTableThe fast CRC table.-
Fields inherited from class totalcross.io.Stream
skipBuffer
-
-
Constructor Summary
Constructors Constructor Description CRC32Stream(Stream s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This method does nothing.longgetValue()Returns the CRC32 data checksum computed so far.intreadBytes(byte[] buf, int start, int count)Computes the checksum for the bytes read from the attached stream.voidreset()Resets the CRC32 data checksum so a new CRC32 can be computed.voidupdate(byte[] buf, int off, int len)Updates the CRC32 with the values of the given buffer.intwriteBytes(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
asInputStream, asOutputStream, asStream, asStream, skipBytes, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
-
-
-
-
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 toint, 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.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
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 IOExceptionComputes the checksum for the bytes read from the attached stream.- Specified by:
readBytesin classStream- Parameters:
buf- the byte array to read data intostart- the start position in the arraycount- 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 IOExceptionComputes the checksum for the given bytes, then write them to the attached stream.- Specified by:
writeBytesin classStream- Parameters:
buf- the byte array to write data fromstart- the start position in the byte arraycount- the number of bytes to write- Returns:
- The number of bytes written to the underlying stream.
- Throws:
IOException
-
-