Example usage for io.netty.buffer ByteBuf clear

List of usage examples for io.netty.buffer ByteBuf clear

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf clear.

Prototype

public abstract ByteBuf clear();

Source Link

Document

Sets the readerIndex and writerIndex of this buffer to 0 .

Usage

From source file:org.opendaylight.protocol.pcep.spi.UtilsTest.java

License:Open Source License

@Test
public void testTlvUtil() {
    byte[] expected = { 0, 4, 0, 4, 1, 2, 3, 4 };
    final ByteBuf out = Unpooled.buffer();
    ByteBuf body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4 });
    TlvUtil.formatTlv(4, body, out);/*from  ww  w.  j av  a2  s  . c  o  m*/
    assertArrayEquals(expected, ByteArray.getAllBytes(out));

    expected = new byte[] { 0, 4, 0, 5, 1, 2, 3, 4, 5, 0, 0, 0 };
    out.clear();
    body = Unpooled.copiedBuffer(new byte[] { 1, 2, 3, 4, 5 });
    TlvUtil.formatTlv(4, body, out);
    assertArrayEquals(expected, ByteArray.getAllBytes(out));
}

From source file:org.opendaylight.protocol.pcep.spi.UtilsTest.java

License:Open Source License

@Test
public void testEROSubobjectUtil() {
    byte[] expected = { (byte) 0x82, 6, 0, 1, 2, 3 };
    final ByteBuf out = Unpooled.buffer();
    final ByteBuf body = Unpooled.copiedBuffer(new byte[] { 0, 1, 2, 3 });
    body.markReaderIndex();// ww  w  . ja  v a2  s.c o  m
    EROSubobjectUtil.formatSubobject(2, true, body, out);
    assertArrayEquals(expected, ByteArray.getAllBytes(out));

    expected = new byte[] { 2, 6, 0, 1, 2, 3 };
    out.clear();
    body.resetReaderIndex();
    EROSubobjectUtil.formatSubobject(2, false, body, out);
    assertArrayEquals(expected, ByteArray.getAllBytes(out));
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteIntegerValue() {
    final byte[] result = { 0, 0, 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.INT_BYTES_LENGTH);
    writeInt(5, output);//from   www  .j a  v  a 2  s .com
    assertArrayEquals(result, output.array());

    output.clear();
    writeInt(null, output);
    assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteShortValue() {
    final byte[] result = { 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    writeShort((short) 5, output);
    assertArrayEquals(result, output.array());

    output.clear();
    writeShort(null, output);/*from w  ww  .j av a  2s.c om*/
    assertArrayEquals(TWO_BYTE_ZEROS, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteMediumValue() {
    final byte[] result = { 0, 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.MEDIUM_BYTES_LENGTH);
    writeMedium(5, output);//from w ww.j  ava2s  .co m
    assertArrayEquals(result, output.array());

    output.clear();
    final byte[] resultZero = { 0, 0, 0 };
    writeMedium(null, output);
    assertArrayEquals(resultZero, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteLongValue() {
    final byte[] result = { 0, 0, 0, 0, 0, 0, 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.LONG_BYTES_LENGTH);
    writeLong((long) 5, output);
    assertArrayEquals(result, output.array());

    output.clear();
    writeLong(null, output);/*  w w w. j  av  a2s .c om*/
    assertArrayEquals(EIGHT_BYTE_ZEROS, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteBooleanValue() {
    final byte[] result = { 1 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    writeBoolean(true, output);/*from  ww  w.java  2 s.  com*/
    assertArrayEquals(result, output.array());

    output.clear();
    writeBoolean(null, output);
    assertArrayEquals(ONE_BYTE_ZERO, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteUnsignedByteValue() {
    final byte[] result = { 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    writeUnsignedByte((short) 5, output);
    assertArrayEquals(result, output.array());

    output.clear();
    writeUnsignedByte(null, output);//ww  w  .  j  a  va 2 s .  c  o  m
    assertArrayEquals(ONE_BYTE_ZERO, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteUnsignedShortValue() {
    final byte[] result = { 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    writeUnsignedShort(5, output);/*from  w ww. java2 s  .co m*/
    assertArrayEquals(result, output.array());

    output.clear();
    writeUnsignedShort(null, output);
    assertArrayEquals(TWO_BYTE_ZEROS, output.array());
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtilTest.java

License:Open Source License

@Test
public void testWriteUnsignedIntValue() {
    final byte[] result = { 0, 0, 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.INT_BYTES_LENGTH);
    ByteBufWriteUtil.writeUnsignedInt((long) 5, output);
    assertArrayEquals(result, output.array());

    output.clear();
    writeUnsignedInt(null, output);/*  w  ww . j  ava  2s.  co  m*/
    assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
}