コード例 #1
0
  @Test
  public void shouldForwardReadCallsBlindly() throws Exception {
    ByteBuf buf = createStrictMock(ByteBuf.class);
    expect(buf.order()).andReturn(BIG_ENDIAN).anyTimes();
    expect(buf.maxCapacity()).andReturn(65536).anyTimes();
    expect(buf.readerIndex()).andReturn(0).anyTimes();
    expect(buf.writerIndex()).andReturn(0).anyTimes();
    expect(buf.capacity()).andReturn(0).anyTimes();

    expect(buf.getBytes(1, (GatheringByteChannel) null, 2)).andReturn(3);
    expect(buf.getBytes(4, (OutputStream) null, 5)).andReturn(buf);
    expect(buf.getBytes(6, (byte[]) null, 7, 8)).andReturn(buf);
    expect(buf.getBytes(9, (ByteBuf) null, 10, 11)).andReturn(buf);
    expect(buf.getBytes(12, (ByteBuffer) null)).andReturn(buf);
    expect(buf.getByte(13)).andReturn(Byte.valueOf((byte) 14));
    expect(buf.getShort(15)).andReturn(Short.valueOf((short) 16));
    expect(buf.getUnsignedMedium(17)).andReturn(18);
    expect(buf.getInt(19)).andReturn(20);
    expect(buf.getLong(21)).andReturn(22L);

    ByteBuffer bb = ByteBuffer.allocate(100);

    expect(buf.nioBuffer(23, 24)).andReturn(bb);
    expect(buf.capacity()).andReturn(27);

    replay(buf);

    ByteBuf roBuf = unmodifiableBuffer(buf);
    assertEquals(3, roBuf.getBytes(1, (GatheringByteChannel) null, 2));
    roBuf.getBytes(4, (OutputStream) null, 5);
    roBuf.getBytes(6, (byte[]) null, 7, 8);
    roBuf.getBytes(9, (ByteBuf) null, 10, 11);
    roBuf.getBytes(12, (ByteBuffer) null);
    assertEquals((byte) 14, roBuf.getByte(13));
    assertEquals((short) 16, roBuf.getShort(15));
    assertEquals(18, roBuf.getUnsignedMedium(17));
    assertEquals(20, roBuf.getInt(19));
    assertEquals(22L, roBuf.getLong(21));

    ByteBuffer roBB = roBuf.nioBuffer(23, 24);
    assertEquals(100, roBB.capacity());
    assertTrue(roBB.isReadOnly());

    assertEquals(27, roBuf.capacity());

    verify(buf);
  }
コード例 #2
0
ファイル: of_factories.java プロジェクト: pooyasp/loxigen
 public OFMessage readFrom(ByteBuf bb) throws OFParseError {
     if(!bb.isReadable())
         return null;
     short wireVersion = U8.f(bb.getByte(bb.readerIndex()));
     OFFactory factory;
     switch (wireVersion) {
     //:: for v in versions:
     case ${v.int_version}:
コード例 #3
0
  /** Tests the "getBufferFor" method */
  @Test
  public void testComponentAtOffset() {
    CompositeByteBuf buf =
        (CompositeByteBuf)
            wrappedBuffer(new byte[] {1, 2, 3, 4, 5}, new byte[] {4, 5, 6, 7, 8, 9, 26});

    // Ensure that a random place will be fine
    assertEquals(5, buf.componentAtOffset(2).capacity());

    // Loop through each byte

    byte index = 0;

    while (index < buf.capacity()) {
      ByteBuf _buf = buf.componentAtOffset(index++);
      assertNotNull(_buf);
      assertTrue(_buf.capacity() > 0);
      assertNotNull(_buf.getByte(0));
      assertNotNull(_buf.getByte(_buf.readableBytes() - 1));
    }
  }
コード例 #4
0
  @Test
  public void testGetReadByte() {
    ByteBuf buf =
        buffer(
            ((ByteBuffer) allocate(2).put(new byte[] {(byte) 1, (byte) 2}).flip())
                .asReadOnlyBuffer());
    Assert.assertEquals(1, buf.getByte(0));
    Assert.assertEquals(2, buf.getByte(1));

    Assert.assertEquals(1, buf.readByte());
    Assert.assertEquals(2, buf.readByte());
    Assert.assertFalse(buf.isReadable());
  }
コード例 #5
0
ファイル: WrappedByteBuf.java プロジェクト: 289/netty
 @Override
 public byte getByte(int index) {
   return buf.getByte(index);
 }