Class PureJavaCrc32

java.lang.Object
org.apache.commons.codec.digest.PureJavaCrc32
All Implemented Interfaces:
Checksum

public class PureJavaCrc32 extends Object implements Checksum
A pure-java implementation of the CRC32 checksum that uses the same polynomial as the built-in native CRC32.

This is to avoid the JNI overhead for certain uses of checksumming where many small pieces of data are checksummed in succession.

The current version is ~10x to 1.8x as fast as Sun's native java.util.zip.CRC32 in Java 1.6

Copied from Apache Hadoop 2.6.3. The code agrees with the following file in the 2.6.3 tag: https://gitbox.apache.org/repos/asf?p=hadoop.git;a=blob_plain; f=hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/PureJavaCrc32.java; hb=2120de588b92b9f22b1cc4188761d6a8c61aa778

This class is Not ThreadSafe

Since:
1.11
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    the current CRC value, bit-flipped
    private static final int[]
    CRC-32 lookup tables generated by the polynomial 0xEDB88320.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new PureJavaCrc32 object.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    void
     
    private void
     
    void
    update(byte[] b, int offset, int len)
     
    final void
    update(int b)
     

    Methods inherited from class java.lang.Object

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

    • T

      private static final int[] T
      CRC-32 lookup tables generated by the polynomial 0xEDB88320. See also TestPureJavaCrc32.Table.
    • crc

      private int crc
      the current CRC value, bit-flipped
  • Constructor Details

    • PureJavaCrc32

      public PureJavaCrc32()
      Create a new PureJavaCrc32 object.
  • Method Details

    • getValue

      public long getValue()
      Specified by:
      getValue in interface Checksum
    • reset

      public void reset()
      Specified by:
      reset in interface Checksum
    • resetCrc

      private void resetCrc()
    • update

      public void update(byte[] b, int offset, int len)
      Specified by:
      update in interface Checksum
    • update

      public final void update(int b)
      Specified by:
      update in interface Checksum