Class SnappyDecompressor


  • final class SnappyDecompressor
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void copyLiteral​(byte[] input, int ipIndex, byte[] output, int opIndex, int length)  
      private static int decompressAllTags​(byte[] input, int inputOffset, int inputSize, byte[] output, int outputOffset)  
      private static int[] decompressTagSlow​(byte[] input, int ipIndex, byte[] output, int outputLimit, int outputOffset, int opIndex)
      This is a second copy of the inner loop of decompressTags used when near the end of the input.
      static int getUncompressedLength​(byte[] compressed, int compressedOffset)  
      private static void incrementalCopy​(byte[] src, int srcIndex, byte[] op, int opIndex, int length)
      Copy "len" bytes from "src" to "op", one byte at a time.
      private static void incrementalCopyFastPath​(byte[] output, int srcIndex, int opIndex, int length)  
      private static int readTrailer​(byte[] data, int index, int bytes)  
      private static int[] readUncompressedLength​(byte[] compressed, int compressedOffset)
      Reads the variable length integer encoded a the specified offset, and returns this length with the number of bytes read.
      static byte[] uncompress​(byte[] compressed, int compressedOffset, int compressedSize)  
      static int uncompress​(byte[] compressed, int compressedOffset, int compressedSize, byte[] uncompressed, int uncompressedOffset)  
      • Methods inherited from class java.lang.Object

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

      • MAX_INCREMENT_COPY_OVERFLOW

        private static final int MAX_INCREMENT_COPY_OVERFLOW
        See Also:
        Constant Field Values
      • wordmask

        private static final int[] wordmask
      • opLookupTable

        private static final short[] opLookupTable
    • Constructor Detail

      • SnappyDecompressor

        SnappyDecompressor()
    • Method Detail

      • uncompress

        public static int uncompress​(byte[] compressed,
                                     int compressedOffset,
                                     int compressedSize,
                                     byte[] uncompressed,
                                     int uncompressedOffset)
                              throws CorruptionException
        Throws:
        CorruptionException
      • decompressAllTags

        private static int decompressAllTags​(byte[] input,
                                             int inputOffset,
                                             int inputSize,
                                             byte[] output,
                                             int outputOffset)
                                      throws CorruptionException
        Throws:
        CorruptionException
      • decompressTagSlow

        private static int[] decompressTagSlow​(byte[] input,
                                               int ipIndex,
                                               byte[] output,
                                               int outputLimit,
                                               int outputOffset,
                                               int opIndex)
                                        throws CorruptionException
        This is a second copy of the inner loop of decompressTags used when near the end of the input. The key difference is the reading of the trailer bytes. The fast code does a blind read of the next 4 bytes as an int, and this code assembles the int byte-by-byte to assure that the array is not over run. The reason this code path is separate is the if condition to choose between these two seemingly small differences costs like 10-20% of the throughput. I'm hoping in future versions of hot-spot this code can be integrated into the main loop but for now it is worth the extra maintenance pain to get the extra 10-20%.
        Throws:
        CorruptionException
      • readTrailer

        private static int readTrailer​(byte[] data,
                                       int index,
                                       int bytes)
      • incrementalCopy

        private static void incrementalCopy​(byte[] src,
                                            int srcIndex,
                                            byte[] op,
                                            int opIndex,
                                            int length)
        Copy "len" bytes from "src" to "op", one byte at a time. Used for handling COPY operations where the input and output regions may overlap. For example, suppose: src == "ab" op == src + 2 len == 20

        After incrementalCopy, the result will have eleven copies of "ab" ababababababababababab Note that this does not match the semantics of either memcpy() or memmove().

      • incrementalCopyFastPath

        private static void incrementalCopyFastPath​(byte[] output,
                                                    int srcIndex,
                                                    int opIndex,
                                                    int length)
      • readUncompressedLength

        private static int[] readUncompressedLength​(byte[] compressed,
                                                    int compressedOffset)
                                             throws CorruptionException
        Reads the variable length integer encoded a the specified offset, and returns this length with the number of bytes read.
        Throws:
        CorruptionException