Package com.peterhi.runtime

Examples of com.peterhi.runtime.BitStream.writeBits()


      for (Map.Entry<BigInteger, Integer> entry : numbers.entrySet()) {
        BigInteger number = entry.getKey();
        Integer size = entry.getValue();

        if (size == Byte.SIZE || size == Short.SIZE || size == Integer.SIZE || size == Long.SIZE) {
          bs.writeBits(number, size);
        }
      }

      assertEquals(Byte.SIZE * 60, bs.available());
      assertEquals(60, bs.bytes());
View Full Code Here


      }
    }
   
    try {
      BitStream bs = new BitStream(32);
      bs.writeBits(null, 0);
      fail();
    } catch (NullPointerException ex) {
    }
   
    try {
View Full Code Here

    } catch (NullPointerException ex) {
    }
   
    try {
      BitStream bs = new BitStream(32);
      bs.writeBits(BigInteger.ONE, -1);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }
 
View Full Code Here

    int bitsWritten = 0;
   
    for (Map.Entry<BigInteger, Integer> entry : numbers.entrySet()) {
      BigInteger number = entry.getKey();
      Integer size = entry.getValue();
      bsw.writeBits(number, size);
      bitsWritten += size;
    }
   
    assertEquals(bitsWritten, bsw.available());
    assertEquals(548, bsw.bytes());
View Full Code Here

  }
 
  @Test
  public void testWriteMarks() throws Exception {
    BitStream bs = new BitStream(2);
    bs.writeBits(BigInteger.ONE, 8);
    bs.setWriteMark();
    bs.writeBits(BigInteger.TEN, 8);
    assertEquals(Byte.SIZE * 2, bs.available());
    assertEquals(2, bs.bytes());
    byte[] data = bs.toByteArray();
View Full Code Here

  @Test
  public void testWriteMarks() throws Exception {
    BitStream bs = new BitStream(2);
    bs.writeBits(BigInteger.ONE, 8);
    bs.setWriteMark();
    bs.writeBits(BigInteger.TEN, 8);
    assertEquals(Byte.SIZE * 2, bs.available());
    assertEquals(2, bs.bytes());
    byte[] data = bs.toByteArray();
    assertEquals(2, data.length);
    assertEquals(1, data[0]);
View Full Code Here

    byte[] data = bs.toByteArray();
    assertEquals(2, data.length);
    assertEquals(1, data[0]);
    assertEquals(10, data[1]);
    bs.goToWriteMark();
    bs.writeBits(BigInteger.ZERO, 8);
    assertEquals(Byte.SIZE * 2, bs.available());
    assertEquals(2, bs.bytes());
    data = bs.toByteArray();
    assertEquals(2, data.length);
    assertEquals(1, data[0]);
View Full Code Here

    data = bs.toByteArray();
    assertEquals(2, data.length);
    assertEquals(1, data[0]);
    assertEquals(0, data[1]);
    bs.clearWriteMark();
    bs.writeBits(BigInteger.TEN, 8);
    data = bs.toByteArray();
    assertEquals(3, data.length);
    assertEquals(Byte.SIZE * 3, bs.available());
    assertEquals(130, bs.bytes());
    bs.goToWriteFromBeginning();
View Full Code Here

    data = bs.toByteArray();
    assertEquals(3, data.length);
    assertEquals(Byte.SIZE * 3, bs.available());
    assertEquals(130, bs.bytes());
    bs.goToWriteFromBeginning();
    bs.writeBits(BigInteger.ZERO, 8);
    bs.writeBits(BigInteger.ZERO, 8);
    data = bs.toByteArray();
    assertEquals(0, data[0]);
    assertEquals(0, data[1]);
  }
View Full Code Here

    assertEquals(3, data.length);
    assertEquals(Byte.SIZE * 3, bs.available());
    assertEquals(130, bs.bytes());
    bs.goToWriteFromBeginning();
    bs.writeBits(BigInteger.ZERO, 8);
    bs.writeBits(BigInteger.ZERO, 8);
    data = bs.toByteArray();
    assertEquals(0, data[0]);
    assertEquals(0, data[1]);
  }
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.