Class SnappyFramed


  • final class SnappyFramed
    extends java.lang.Object
    Constants and utilities for implementing x-snappy-framed.
    Since:
    1.1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      SnappyFramed()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.Class<?> lookupClassQuietly​(java.lang.String name)  
      static int mask​(int crc)
      Checksums are not stored directly, but masked, as checksumming data and then its own checksum can be problematic.
      static int maskedCrc32c​(byte[] data)  
      static int maskedCrc32c​(byte[] data, int offset, int length)  
      (package private) static int readBytes​(java.nio.channels.ReadableByteChannel source, java.nio.ByteBuffer dest)  
      (package private) static void releaseDirectByteBuffer​(java.nio.ByteBuffer buffer)
      Provides jvm implementation specific operation to aggressively release resources associated with buffer.
      (package private) static int skip​(java.nio.channels.ReadableByteChannel source, int skip, java.nio.ByteBuffer buffer)  
      • Methods inherited from class java.lang.Object

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

      • SUN_DIRECT_BUFFER

        private static final java.lang.Class<? extends java.nio.ByteBuffer> SUN_DIRECT_BUFFER
        Sun specific mechanisms to clean up resources associated with direct byte buffers.
      • SUN_BUFFER_CLEANER

        private static final java.lang.reflect.Method SUN_BUFFER_CLEANER
      • SUN_CLEANER_CLEAN

        private static final java.lang.reflect.Method SUN_CLEANER_CLEAN
      • HEADER_BYTES

        public static final byte[] HEADER_BYTES
        The header consists of the stream identifier flag, 3 bytes indicating a length of 6, and "sNaPpY" in ASCII.
    • Constructor Detail

      • SnappyFramed

        SnappyFramed()
    • 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)
        Checksums are not stored directly, but masked, as checksumming data and then its own checksum can be problematic. The masking is the same as used in Apache Hadoop: Rotate the checksum by 15 bits, then add the constant 0xa282ead8 (using wraparound as normal for unsigned integers). This is equivalent to the following C code:

         uint32_t mask_checksum(uint32_t x) {
             return ((x >> 15) | (x << 17)) + 0xa282ead8;
         }
         
      • readBytes

        static final int readBytes​(java.nio.channels.ReadableByteChannel source,
                                   java.nio.ByteBuffer dest)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • skip

        static int skip​(java.nio.channels.ReadableByteChannel source,
                        int skip,
                        java.nio.ByteBuffer buffer)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • lookupClassQuietly

        private static java.lang.Class<?> lookupClassQuietly​(java.lang.String name)
      • releaseDirectByteBuffer

        static void releaseDirectByteBuffer​(java.nio.ByteBuffer buffer)
        Provides jvm implementation specific operation to aggressively release resources associated with buffer.
        Parameters:
        buffer - The ByteBuffer to release. Must not be null. Must be direct.