Example usage for io.netty.buffer ByteBuf array

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

Introduction

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

Prototype

public abstract byte[] array();

Source Link

Document

Returns the backing byte array of this buffer.

Usage

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);// w  w  w. j a v a2  s.c om
    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();/* w ww. j a  va  2  s . c o m*/
    writeShort(null, output);
    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  w  w.j  a  v  a2s  .c om
    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();/*from  w  ww. j  a v a 2  s. co  m*/
    writeLong(null, output);
    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);/*ww w .ja v a  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();//from   w ww  .j  a v a2s  .  c  o  m
    writeUnsignedByte(null, output);
    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);/*w ww.  ja v a2s  .  c om*/
    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();//from  w w w. j a va 2 s .  co  m
    writeUnsignedInt(null, output);
    assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
}

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

License:Open Source License

@Test
public void testWriteUnsignedLongValue() {
    final byte[] result = { 0, 0, 0, 0, 0, 0, 0, 5 };
    final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.LONG_BYTES_LENGTH);
    writeUnsignedLong(new BigInteger("5"), output);
    assertArrayEquals(result, output.array());

    output.clear();//from   w ww  .j  a  v a  2 s  .c  o  m
    writeUnsignedLong(null, output);
    assertArrayEquals(EIGHT_BYTE_ZEROS, output.array());
}

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

License:Open Source License

@Test
public void testWriteIpv4Address() {
    final byte[] result = { 127, 0, 0, 1 };
    final ByteBuf output = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
    writeIpv4Address(new Ipv4Address("127.0.0.1"), output);
    assertArrayEquals(result, output.array());

    output.clear();//from   w w  w . j  a v  a 2s .  com
    writeIpv4Address(null, output);
    assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
}