Package totalcross.io

Class 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 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.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.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 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