Package com.peterhi.runtime

Examples of com.peterhi.runtime.BitStream


    assertEquals(2, bs.bytes());
  }
 
  @Test
  public void testClear() throws Exception {
    BitStream bs = new BitStream(2);
    bs.writeBit(1);
    bs.alignRead();
    bs.writeBit(0);
    bs.writeBit(1);
    assertEquals(1, bs.readBit());
    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


    assertEquals(2, bs.bytes());
  }
 
  @Test
  public void testSkipWrite() throws Exception {
    BitStream bs0 = new BitStream(1);
    bs0.writeBit(1);
    bs0.alignWrite();
    bs0.writeBit(1);
    BitStream bs1 = new BitStream(1);
    bs1.writeBit(1);
    bs1.skipWrite(7);
    bs1.writeBit(1);
    byte[] data = new byte[] { 1, 1 };
    assertArrayEquals(data, bs0.toByteArray());
    assertArrayEquals(data, bs1.toByteArray());
   
    try {
      bs0.skipWrite(-1);
      fail();
    } catch (IllegalArgumentException ex) {
View Full Code Here

  }
 
  @Test
  public void testSkipRead() throws Exception {
    byte[] data = new byte[] { 1, 1 };
    BitStream bs0 = new BitStream(data, 0, Byte.SIZE * data.length);
    BitStream bs1 = new BitStream(data, 0, Byte.SIZE * data.length);
    assertEquals(1, bs0.readBit());
    assertEquals(1, bs1.readBit());
    bs0.alignRead();
    bs1.skipRead(7);
    assertEquals(1, bs0.readBit());
    assertEquals(1, bs1.readBit());
    assertEquals(7, bs0.available());
    assertEquals(7, bs1.available());

    assertEquals(7, bs0.skipRead(7));
    assertEquals(0, bs0.available());
    assertEquals(0, bs0.skipRead(7));
   
View Full Code Here

  }
 
  @Test
  public void testConstructorCapacity() throws Exception {
    {
      BitStream bs = new BitStream(32);
      assertEquals(0, bs.available());
      assertEquals(32, bs.bytes());
    }
   
    try {
      BitStream bs = new BitStream(-1);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }
View Full Code Here

  }
 
  @Test
  public void testConstructorBufOffLen() throws Exception {
    {
      BitStream bs = new BitStream(new byte[32], Byte.SIZE * 16, Byte.SIZE * 16);
      assertEquals(Byte.SIZE * 16, bs.available());
      assertEquals(16, bs.bytes());
    }
   
    try {
      BitStream bs = new BitStream(null, 0, 1);
      fail();
    } catch (NullPointerException ex) {
    }
   
    try {
      BitStream bs = new BitStream(new byte[1], -1, 1);
      fail();
    } catch (IndexOutOfBoundsException ex) {
    }
   
    try {
      BitStream bs = new BitStream(new byte[1], 1, -1);
      fail();
    } catch (IndexOutOfBoundsException ex) {
    }
   
    try {
      BitStream bs = new BitStream(new byte[1], 1, Byte.SIZE);
      fail();
    } catch (IndexOutOfBoundsException ex) {
    }
  }
View Full Code Here

  }

  @Test
  public void testAvailable() throws Exception {
    {
      BitStream bs = new BitStream(32);
      assertEquals(0, bs.available());
      assertEquals(32, bs.bytes());
    }
   
    {
      byte[] data = new byte[32];
      BitStream bs = new BitStream(data, 0, Byte.SIZE * data.length);
      assertEquals(Byte.SIZE * data.length, bs.available());
      assertEquals(data.length, bs.bytes());
    }
   
    {
      BitStream bs = new BitStream(32);
      bs.writeBit(1);
      assertEquals(1, bs.available());
      assertEquals(32, bs.bytes());
    }
  }
View Full Code Here

  }
 
  @Test
  public void testSize() throws Exception {
    {
      BitStream bs = new BitStream(32);
      assertEquals(0, bs.available());
      assertEquals(32, bs.bytes());
    }
   
    {
      byte[] data = new byte[32];
      BitStream bs = new BitStream(data, Byte.SIZE * 16, Byte.SIZE * 16);
      assertEquals(Byte.SIZE * 16, bs.available());
      assertEquals(16, bs.bytes());
    }
   
    {
      BitStream bs = new BitStream(1);
     
      for (int i = 0; i < 9; i++) {
        bs.writeBit(1);
      }
     
      assertEquals(9, bs.available());
      assertEquals(129, bs.bytes());
    }
  }
View Full Code Here

TOP

Related Classes of com.peterhi.runtime.BitStream

Copyright © 2018 www.massapicom. 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.