Пример #1
0
 public void testBitIOValues() {
   BitIOWriter writer = new BitIOWriter();
   writer.writeValue(0x55, 7);
   writer.writeValue(0x245, 10);
   writer.flush();
   byte[] result = writer.toByteArray();
   byte[] expected = {(byte) 0xab, (byte) 0x22, (byte) 0x80};
   assertEqualsByteArray(expected, result);
 }
Пример #2
0
 private void encode() {
   int maxIndex = length1 + PRELOAD_SIZE;
   initializeModel();
   bits.writeValue(length1, 24);
   int limit = length1 + PRELOAD_SIZE;
   int[] dist = new int[1];
   for (int i = PRELOAD_SIZE; i < limit; ) {
     int here = i;
     int len = makeCopyDecision(i++, dist);
     if (len > 0) {
       int distRanges = getNumDistRanges(dist[0]);
       encodeLength(len, dist[0], distRanges);
       encodeDistance2(dist[0], distRanges);
       for (int j = 1; j < len; j++) {
         updateModel(i++);
       }
     } else {
       byte c = buf[here];
       if (here >= 2 && c == buf[here - 2]) {
         symEncoder.writeSymbol(dup2);
       } else if (here >= 4 && c == buf[here - 4]) {
         symEncoder.writeSymbol(dup4);
       } else if (here >= 6 && c == buf[here - 6]) {
         symEncoder.writeSymbol(dup6);
       } else {
         symEncoder.writeSymbol(buf[here] & 0xff);
       }
     }
   }
 }