Пример #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 write(byte[] dataIn) {
   bits.writeBit(usingRunLength);
   length1 = dataIn.length;
   // If we want to do runlengths, here's the place, but I'm not convinced it's useful
   setDistRange(length1);
   distEncoder = new HuffmanEncoder(bits, 1 << DIST_WIDTH);
   lenEncoder = new HuffmanEncoder(bits, 1 << LEN_WIDTH);
   symEncoder = new HuffmanEncoder(bits, numSyms);
   buf = new byte[PRELOAD_SIZE + length1];
   System.arraycopy(dataIn, 0, buf, PRELOAD_SIZE, length1);
   encode();
   bits.flush();
 }
Пример #3
0
 public void testBitIOBool() {
   BitIOWriter writer = new BitIOWriter();
   writer.writeBit(true);
   writer.writeBit(false);
   writer.writeBit(true);
   writer.writeBit(true);
   writer.writeBit(false);
   writer.writeBit(false);
   writer.writeBit(true);
   writer.writeBit(false);
   writer.writeBit(true);
   writer.flush();
   byte[] result = writer.toByteArray();
   byte[] expected = {(byte) 0xb2, (byte) 0x80};
   assertEqualsByteArray(expected, result);
 }
Пример #4
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);
       }
     }
   }
 }
Пример #5
0
 private byte[] toByteArray() {
   return bits.toByteArray();
 }