Class CRC32

java.lang.Object
net.mtrop.doom.struct.io.CRC32

public class CRC32 extends Object
This is an implementation of the CRC32 algorithm, used for CRC checksumming of byte arrays and streams.
Author:
Matthew Tropiano
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Known polynomials: Castagnioli (iSCSI).
    static final int
    Default often-used CRC polynomial.
    static final int
    Known polynomials: IEEE CRC polynomial (used in Ethernet and PNG and a bunch of other things).
    static final int
    Known polynomials: Koopman.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new CRC32 calculator using the POLYNOMIAL_DEFAULT CRC32 polynomial.
    CRC32(int polynomial)
    Creates a new CRC32 calculator using a specific CRC32 polynomial.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    createCRC32(byte[] buf)
    Generates a CRC32 checksum for a set of bytes.
    int
    createCRC32(byte[] buf, int len)
    Generates a CRC32 checksum for a set of bytes.
    int
    createCRC32(int startCRC, byte[] buf)
    Generates a CRC32 checksum for a set of bytes.
    int
    createCRC32(int startCRC, byte[] buf, int len)
    Generates a CRC32 checksum for a set of bytes.
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POLYNOMIAL_DEFAULT

      public static final int POLYNOMIAL_DEFAULT
      Default often-used CRC polynomial.
      See Also:
    • POLYNOMIAL_IEEE

      public static final int POLYNOMIAL_IEEE
      Known polynomials: IEEE CRC polynomial (used in Ethernet and PNG and a bunch of other things).
      See Also:
    • POLYNOMIAL_CASTAGNIOLI

      public static final int POLYNOMIAL_CASTAGNIOLI
      Known polynomials: Castagnioli (iSCSI).
      See Also:
    • POLYNOMIAL_KOOPMAN

      public static final int POLYNOMIAL_KOOPMAN
      Known polynomials: Koopman.
      See Also:
  • Constructor Details

    • CRC32

      public CRC32()
      Creates a new CRC32 calculator using the POLYNOMIAL_DEFAULT CRC32 polynomial.
    • CRC32

      public CRC32(int polynomial)
      Creates a new CRC32 calculator using a specific CRC32 polynomial.
      Parameters:
      polynomial - the polynomial to use.
  • Method Details

    • createCRC32

      public int createCRC32(int startCRC, byte[] buf)
      Generates a CRC32 checksum for a set of bytes. This will generate a checksum for all of the bytes in the array.
      Parameters:
      startCRC - the starting checksum value.
      buf - the bytes to generate the checksum for.
      Returns:
      a CRC32 checksum of the desired bytes.
    • createCRC32

      public int createCRC32(byte[] buf)
      Generates a CRC32 checksum for a set of bytes. Uses a starting checksum value of -1 (0xffffffff). This will generate a checksum for all of the bytes in the array.
      Parameters:
      buf - the bytes to generate the checksum for.
      Returns:
      a CRC32 checksum of the desired bytes.
    • createCRC32

      public int createCRC32(byte[] buf, int len)
      Generates a CRC32 checksum for a set of bytes. Uses a starting checksum value of -1 (0xffffffff).
      Parameters:
      buf - the bytes to generate the checksum for.
      len - the amount of bytes in the array to use.
      Returns:
      a CRC32 checksum of the desired bytes.
    • createCRC32

      public int createCRC32(int startCRC, byte[] buf, int len)
      Generates a CRC32 checksum for a set of bytes.
      Parameters:
      startCRC - the starting checksum value.
      buf - the bytes to generate the checksum for.
      len - the amount of bytes in the array to use.
      Returns:
      a CRC32 checksum of the desired bytes.
    • getPolynomial

      public int getPolynomial()
      Returns:
      the polynomial used for this CRC object.