Package net.mtrop.doom.struct.io
Class CRC32
java.lang.Object
net.mtrop.doom.struct.io.CRC32
This is an implementation of the CRC32 algorithm,
used for CRC checksumming of byte arrays and streams.
- Author:
- Matthew Tropiano
-
Field Summary
Modifier and TypeFieldDescriptionstatic 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
-
Method Summary
Modifier and TypeMethodDescriptionint
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
-
Field Details
-
POLYNOMIAL_DEFAULT
public static final int POLYNOMIAL_DEFAULTDefault often-used CRC polynomial.- See Also:
-
POLYNOMIAL_IEEE
public static final int POLYNOMIAL_IEEEKnown polynomials: IEEE CRC polynomial (used in Ethernet and PNG and a bunch of other things).- See Also:
-
POLYNOMIAL_CASTAGNIOLI
public static final int POLYNOMIAL_CASTAGNIOLIKnown polynomials: Castagnioli (iSCSI).- See Also:
-
POLYNOMIAL_KOOPMAN
public static final int POLYNOMIAL_KOOPMANKnown 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.
-