@Override
  public Integer read(BitInputStream bis) throws IOException {
    long buf = 0; // huffman code
    int bitsRead = 0;
    for (int len : codeLentghSorted) {
      buf = buf << (len - bitsRead);

      long readLongBits = bis.readLongBits(len - bitsRead);

      buf = buf | readLongBits;

      bitsRead = len;
      Map<Long, Integer> codeMap = codeMaps[len];
      Integer result = codeMap.get(buf);
      if (result != null) {
        return result;
      }
    }
    throw new RuntimeException(
        "Bit code not found. Current state: " + bitsRead + " bits read, buf=" + buf);
  }
Example #2
0
 @Override
 public final Integer read(final BitInputStream bitInputStream) throws IOException {
   return bitInputStream.readBits(readNofBits) - offset;
 }