Class HuffmanDecoder

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    class HuffmanDecoder
    extends java.lang.Object
    implements java.io.Closeable
    • Field Detail

      • RUN_LENGTH_TABLE

        private static final short[] RUN_LENGTH_TABLE
         --------------------------------------------------------------------
         idx  xtra  base     idx  xtra  base     idx  xtra  base
         --------------------------------------------------------------------
         257   0     3       267   1   15,16     277   4   67-82
         258   0     4       268   1   17,18     278   4   83-98
         259   0     5       269   2   19-22     279   4   99-114
         260   0     6       270   2   23-26     280   4   115-130
         261   0     7       271   2   27-30     281   5   131-162
         262   0     8       272   2   31-34     282   5   163-194
         263   0     9       273   3   35-42     283   5   195-226
         264   0     10      274   3   43-50     284   5   227-257
         265   1     11,12   275   3   51-58     285   16  3
         266   1     13,14   276   3   59-66
         --------------------------------------------------------------------
         
        value = (base of run length) << 5 | (number of extra bits to read)
      • DISTANCE_TABLE

        private static final int[] DISTANCE_TABLE
         --------------------------------------------------------------------
         idx  xtra  dist     idx  xtra  dist       idx  xtra  dist
         --------------------------------------------------------------------
         0    0     1        10   4     33-48      20    9   1025-1536
         1    0     2        11   4     49-64      21    9   1537-2048
         2    0     3        12   5     65-96      22   10   2049-3072
         3    0     4        13   5     97-128     23   10   3073-4096
         4    1     5,6      14   6     129-192    24   11   4097-6144
         5    1     7,8      15   6     193-256    25   11   6145-8192
         6    2     9-12     16   7     257-384    26   12   8193-12288
         7    2     13-16    17   7     385-512    27   12   12289-16384
         8    3     17-24    18   8     513-768    28   13   16385-24576
         9    3     25-32    19   8     769-1024   29   13   24577-32768
         30   14   32769-49152
         31   14   49153-65536
         --------------------------------------------------------------------
         
        value = (base of distance) << 4 | (number of extra bits to read)
      • CODE_LENGTHS_ORDER

        private static final int[] CODE_LENGTHS_ORDER
        When using dynamic huffman codes the order in which the values are stored follows the positioning below
      • FIXED_LITERALS

        private static final int[] FIXED_LITERALS
        Huffman Fixed Literal / Distance tables for mode 1
      • FIXED_DISTANCE

        private static final int[] FIXED_DISTANCE
      • finalBlock

        private boolean finalBlock
      • in

        private final java.io.InputStream in
    • Constructor Detail

      • HuffmanDecoder

        HuffmanDecoder​(java.io.InputStream in)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • decode

        public int decode​(byte[] b)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • decode

        public int decode​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getBytesRead

        long getBytesRead()
        Since:
        1.17
      • switchToUncompressedState

        private void switchToUncompressedState()
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readDynamicTables

        private int[][] readDynamicTables()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • available

        int available()
               throws java.io.IOException
        Throws:
        java.io.IOException
      • populateDynamicTables

        private static void populateDynamicTables​(BitInputStream reader,
                                                  int[] literals,
                                                  int[] distances)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • getCodes

        private static int[] getCodes​(int[] litTable)
      • readBits

        private long readBits​(int numBits)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readBits

        private static long readBits​(BitInputStream reader,
                                     int numBits)
                              throws java.io.IOException
        Throws:
        java.io.IOException