Package com.peterhi.runtime

Examples of com.peterhi.runtime.Buffer.readable()


      // 00[111111 1111]0000 ==> not aligned
     
      byte[] existingData = new byte[] { -1, -1 };
      Buffer existingDataOffsetLengthBitsNotAligned = new Buffer(existingData, 4, 10, false);
      assertEquals(2, existingDataOffsetLengthBitsNotAligned.size());
      assertEquals(14, existingDataOffsetLengthBitsNotAligned.readable());
      assertEquals(14, existingDataOffsetLengthBitsNotAligned.written());
      assertEquals(2, existingDataOffsetLengthBitsNotAligned.writable());
      assertEquals(0, existingDataOffsetLengthBitsNotAligned.read());
      existingDataOffsetLengthBitsNotAligned.skip(3);
      assertEquals(1, existingDataOffsetLengthBitsNotAligned.read());
View Full Code Here


      // 0000000[1 11111111] ==> aligned
     
      byte[] existingData = new byte[] { -1, -1 };
      Buffer existingDataOffsetLengthBitsAligned = new Buffer(existingData, 4, 9, true);
      assertEquals(2, existingDataOffsetLengthBitsAligned.size());
      assertEquals(9, existingDataOffsetLengthBitsAligned.readable());
      assertEquals(9, existingDataOffsetLengthBitsAligned.written());
      assertEquals(7, existingDataOffsetLengthBitsAligned.writable());
      assertEquals(1, existingDataOffsetLengthBitsAligned.read());
      existingDataOffsetLengthBitsAligned.skip(7);
      assertEquals(1, existingDataOffsetLengthBitsAligned.read());
View Full Code Here

  }
 
  @Test
  public void testSizeFunctions() throws Exception {
    Buffer testBuffer = new Buffer(1);
    assertEquals(0, testBuffer.readable());
    assertEquals(Byte.SIZE, testBuffer.writable());
    assertEquals(0, testBuffer.written());
    assertEquals(1, testBuffer.size());
  }
 
View Full Code Here

    assertEquals(0, readWriteBuffer.read());
    assertEquals(1, readWriteBuffer.read());
    assertEquals(-1, readWriteBuffer.read());
    assertEquals(Buffer.CAPACITY_DEFAULT, readWriteBuffer.size());
    assertEquals(Byte.SIZE * Buffer.CAPACITY_DEFAULT - 3, readWriteBuffer.writable());
    assertEquals(0, readWriteBuffer.readable());
    assertEquals(3, readWriteBuffer.written());
  }
 
  @Test
  public void testReadWriteBitAsBoolean() throws Exception {
View Full Code Here

    assertEquals(false, readWriteBuffer.readAsBoolean());
    assertEquals(true, readWriteBuffer.readAsBoolean());
    assertEquals(-1, readWriteBuffer.read());
    assertEquals(Buffer.CAPACITY_DEFAULT, readWriteBuffer.size());
    assertEquals(Byte.SIZE * Buffer.CAPACITY_DEFAULT - 3, readWriteBuffer.writable());
    assertEquals(0, readWriteBuffer.readable());
    assertEquals(3, readWriteBuffer.written());
  }
 
  @Test
  public void testReadWriteBits() throws Exception {
View Full Code Here

  @Test
  public void testConstructors() throws Exception {
    {
      Buffer capacityInBytes = new Buffer(Buffer.CAPACITY_DEFAULT);
      assertEquals(Buffer.CAPACITY_DEFAULT, capacityInBytes.size());
      assertEquals(0, capacityInBytes.readable());
      assertEquals(Byte.SIZE * Buffer.CAPACITY_DEFAULT, capacityInBytes.writable());
      assertEquals(0, capacityInBytes.written());
    }
   
    try {
View Full Code Here

    }
   
    {
      Buffer defaultConstructor = new Buffer();
      assertEquals(Buffer.CAPACITY_DEFAULT, defaultConstructor.size());
      assertEquals(0, defaultConstructor.readable());
      assertEquals(Byte.SIZE * Buffer.CAPACITY_DEFAULT, defaultConstructor.writable());
      assertEquals(0, defaultConstructor.written());
    }
   
    {
View Full Code Here

   
    {
      byte[] existingData = new byte[32];
      Buffer usingExistingData = new Buffer(existingData);
      assertEquals(existingData.length, usingExistingData.size());
      assertEquals(Byte.SIZE * existingData.length, usingExistingData.readable());
      assertEquals(0, usingExistingData.writable());
      assertEquals(Byte.SIZE * existingData.length, usingExistingData.written());
    }
   
    try {
View Full Code Here

    {
      byte[] existingData = new byte[32];
      Buffer existingDataOffsetLength = new Buffer(existingData, 0, existingData.length);
      assertEquals(existingData.length, existingDataOffsetLength.size());
      assertEquals(existingData.length, existingDataOffsetLength.size());
      assertEquals(Byte.SIZE * existingData.length, existingDataOffsetLength.readable());
      assertEquals(0, existingDataOffsetLength.writable());
      assertEquals(Byte.SIZE * existingData.length, existingDataOffsetLength.written());
    }
   
    try {
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.