Class Crc32C

  • All Implemented Interfaces:

    public final class Crc32C
    extends java.lang.Object
    A pure-java implementation of the CRC32 checksum that uses the CRC32-C polynomial, the same polynomial used by iSCSI and implemented on many Intel chipsets supporting SSE4.2. This class implementation is copied from the org.iq80.snappy.Crc32C implementation because it was stupidly made package private for no good reason. Note that Java9 will provide its own implementation of CRC32-C which may have scope for native acceleration.
    • Constructor Summary

      Constructor Description
      Create a new PureJavaCrc32 object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getIntValue()  
      int getMaskedValue()  
      long getValue()  
      static int mask​(int crc)
      Return a masked representation of crc.
      static int maskedCrc32c​(byte[] data)  
      static int maskedCrc32c​(byte[] data, int offset, int length)  
      void reset()  
      static int unmask​(int maskedCrc)
      Return the crc whose masked representation is masked_crc.
      void update​(byte[] b)  
      void update​(byte[] b, int off, int len)  
      void update​(int b)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface

    • Constructor Detail

      • Crc32C

        public Crc32C()
        Create a new PureJavaCrc32 object.
    • Method Detail

      • maskedCrc32c

        public static int maskedCrc32c​(byte[] data)
      • maskedCrc32c

        public static int maskedCrc32c​(byte[] data,
                                       int offset,
                                       int length)
      • mask

        public static int mask​(int crc)
        Return a masked representation of crc.

        Motivation: it is problematic to compute the CRC of a string that contains embedded CRCs. Therefore we recommend that CRCs stored somewhere (e.g., in files) should be masked before being stored.

      • unmask

        public static int unmask​(int maskedCrc)
        Return the crc whose masked representation is masked_crc.
      • getMaskedValue

        public int getMaskedValue()
      • getIntValue

        public int getIntValue()
      • getValue

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

        public void reset()
        Specified by:
        reset in interface
      • update

        public void update​(byte[] b)
        Specified by:
        update in interface
      • update

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

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