Package com.peterhi.runtime

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


      }

      assertEquals(Byte.SIZE * 60, bs.available());
      assertEquals(60, bs.bytes());
     
      byte[] data = bs.toByteArray();
      DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));
     
      for (Map.Entry<BigInteger, Integer> entry : numbers.entrySet()) {
        BigInteger number = entry.getKey();
        Integer size = entry.getValue();
View Full Code Here


    }
   
    assertEquals(bitsWritten, bsw.available());
    assertEquals(548, bsw.bytes());
   
    byte[] data = bsw.toByteArray();
    BitStream bsr = new BitStream(data, 0, bitsWritten);
   
    for (Map.Entry<BigInteger, Integer> entry : numbers.entrySet()) {
      BigInteger number = entry.getKey();
      Integer size = entry.getValue();
View Full Code Here

    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]);
    assertEquals(10, data[1]);
    bs.goToWriteMark();
    bs.writeBits(BigInteger.ZERO, 8);
View Full Code Here

    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]);
    assertEquals(0, data[1]);
    bs.clearWriteMark();
    bs.writeBits(BigInteger.TEN, 8);
View Full Code Here

    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();
    bs.writeBits(BigInteger.ZERO, 8);
View Full Code Here

    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]);
  }
 
  @Test
View Full Code Here

  public void testAlignWrite() throws Exception {
    BitStream bs = new BitStream(2);
    bs.writeBit(1);
    bs.alignWrite();
    bs.writeBit(1);
    byte[] data = bs.toByteArray();
    assertEquals(1, data[0]);
    assertEquals(1, data[1]);
    assertEquals(9, bs.available());
    assertEquals(2, bs.bytes());
  }
View Full Code Here

  @Test
  public void testToByteArray() throws Exception {
    BitStream bs = new BitStream(2);
    bs.writeBits(BigInteger.valueOf(255), 8);
    bs.writeBits(BigInteger.valueOf(255), 8);
    byte[] data = bs.toByteArray();
    assertEquals(-1, data[0]);
    assertEquals(-1, data[1]);
    bs.readBits(4, true);
    data = bs.toByteArray();
    assertEquals(-1, data[0]);
View Full Code Here

    bs.writeBits(BigInteger.valueOf(255), 8);
    byte[] data = bs.toByteArray();
    assertEquals(-1, data[0]);
    assertEquals(-1, data[1]);
    bs.readBits(4, true);
    data = bs.toByteArray();
    assertEquals(-1, data[0]);
    assertEquals(15, data[1]);
    assertEquals(12, bs.available());
    assertEquals(2, bs.bytes());
  }
View Full Code Here

    bs.clear();
    assertEquals(-1, bs.readBit());
    assertEquals(0, bs.available());
    assertEquals(2, bs.bytes());
    bs.writeBit(1);
    byte[] data = bs.toByteArray();
    assertEquals(1, data[0]);
    assertEquals(1, bs.available());
    assertEquals(2, bs.bytes());
  }
 
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.