Class Lz4XXHash32

  • All Implemented Interfaces:
    java.util.zip.Checksum

    public final class Lz4XXHash32
    extends java.lang.Object
    A special-purpose ByteBufChecksum implementation for use with Lz4FrameEncoder and Lz4FrameDecoder. StreamingXXHash32.asChecksum() has a particularly nasty implementation of Checksum.update(int) that allocates a single-element byte array for every invocation. In addition to that, it doesn't implement an overload that accepts a ByteBuffer as an argument. Combined, this means that we can't use ReflectiveByteBufChecksum at all, and can't use SlowByteBufChecksum because of its atrocious performance with direct byte buffers (allocating an array and making a JNI call for every byte checksummed might be considered sub-optimal by some). Block version of xxHash32 (XXHash32), however, does provide XXHash32.hash(ByteBuffer, int) method that is efficient and does exactly what we need, with a caveat that we can only invoke it once before having to reset. This, however, is fine for our purposes, given the way we use it in Lz4FrameEncoder and Lz4FrameDecoder: reset(), followed by one update(), followed by getValue().
    • Constructor Summary

      Constructors 
      Constructor Description
      Lz4XXHash32​(int seed)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getValue()  
      void reset()  
      void update​(byte[] b, int off, int len)  
      void update​(int b)  
      void update​(ByteBuf b, int off, int len)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.zip.Checksum

        update, update
    • Constructor Detail

      • Lz4XXHash32

        public Lz4XXHash32​(int seed)
    • Method Detail

      • update

        public void update​(int b)
      • update

        public void update​(byte[] b,
                           int off,
                           int len)
      • update

        public void update​(ByteBuf b,
                           int off,
                           int len)
        See Also:
        Checksum.update(byte[], int, int)
      • getValue

        public long getValue()
      • reset

        public void reset()