protected void checkPrefixCodec(PrefixCodec codec, Random r) throws IOException {
    int[] symbol = new int[100];
    BooleanArrayList bits = new BooleanArrayList();
    for (int i = 0; i < symbol.length; i++) symbol[i] = r.nextInt(codec.size());
    for (int i = 0; i < symbol.length; i++) {
      BitVector word = codec.codeWords()[symbol[i]];
      for (int j = 0; j < word.size(); j++) bits.add(word.get(j));
    }

    BooleanIterator booleanIterator = bits.iterator();
    Decoder decoder = codec.decoder();
    for (int i = 0; i < symbol.length; i++) {
      assertEquals(decoder.decode(booleanIterator), symbol[i]);
    }

    FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
    OutputBitStream obs = new OutputBitStream(fbaos, 0);
    obs.write(bits.iterator());
    obs.flush();
    InputBitStream ibs = new InputBitStream(fbaos.array);

    for (int i = 0; i < symbol.length; i++) {
      assertEquals(decoder.decode(ibs), symbol[i]);
    }
  }
 @Override
 public int encode(final int symbol, final OutputBitStream obs) throws IOException {
   return obs.writeLong(longCodeWord[symbol], length[symbol]);
 }