Example usage for io.netty.buffer Unpooled buffer

List of usage examples for io.netty.buffer Unpooled buffer

Introduction

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

Prototype

public static ByteBuf buffer() 

Source Link

Document

Creates a new big-endian Java heap buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand.

Usage

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addValues() throws Exception {

    CommandArgs<String, String> args = new CommandArgs<>(codec).addValues(Arrays.asList("1", "2"));

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);/*from w w w .  j av  a 2  s.  co  m*/

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$1\r\n" + "1\r\n" + "$1\r\n" + "2\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addByte() throws Exception {

    CommandArgs<String, String> args = new CommandArgs<>(codec).add("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);//from w w w  . ja v a2 s .  c om

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addByteUsingDirectByteCodec() throws Exception {

    CommandArgs<byte[], byte[]> args = new CommandArgs<>(CommandArgs.ExperimentalByteArrayCodec.INSTANCE)
            .add("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);// w w  w. ja  v a2  s .  com

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addValueUsingDirectByteCodec() throws Exception {

    CommandArgs<byte[], byte[]> args = new CommandArgs<>(CommandArgs.ExperimentalByteArrayCodec.INSTANCE)
            .addValue("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);//from   w ww.j  a v  a 2s . c  o m

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addKeyUsingDirectByteCodec() throws Exception {

    CommandArgs<byte[], byte[]> args = new CommandArgs<>(CommandArgs.ExperimentalByteArrayCodec.INSTANCE)
            .addValue("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);//from   w  w  w.  ja v a 2s .co m

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addByteUsingByteCodec() throws Exception {

    CommandArgs<byte[], byte[]> args = new CommandArgs<>(ByteArrayCodec.INSTANCE).add("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);//from  www  . ja v a2 s  .c  om

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addValueUsingByteCodec() throws Exception {

    CommandArgs<byte[], byte[]> args = new CommandArgs<>(ByteArrayCodec.INSTANCE).addValue("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);/*from  w w  w  .ja v a2s  .  c  o m*/

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.lambdaworks.redis.protocol.CommandArgsTest.java

License:Apache License

@Test
public void addKeyUsingByteCodec() throws Exception {

    CommandArgs<byte[], byte[]> args = new CommandArgs<>(ByteArrayCodec.INSTANCE).addValue("one".getBytes());

    ByteBuf buffer = Unpooled.buffer();
    args.encode(buffer);/*from w w  w. j a v  a2 s  . c  om*/

    ByteBuf expected = Unpooled.buffer();
    expected.writeBytes(("$3\r\n" + "one\r\n").getBytes());

    assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII));
}

From source file:com.linecorp.armeria.client.encoding.AbstractStreamDecoderTest.java

License:Apache License

@Test
public void decodedBufferShouldNotLeak() {
    final StreamDecoder decoder = newDecoder();
    final ByteBuf buf = Unpooled.buffer();
    decoder.decode(new ByteBufHttpData(buf, false));
    assertThat(buf.refCnt()).isZero();/*w  w  w . ja v a 2  s.  c  om*/
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

private static DnsRecord newCompatibleAddressRecord(String name, String ipV4Addr) {
    final ByteBuf content = Unpooled.buffer();
    content.writeZero(12);/*from   w w w.  jav a 2s.co m*/
    content.writeBytes(NetUtil.createByteArrayFromIpAddressString(ipV4Addr));
    return new DefaultDnsRawRecord(name, AAAA, 60, content);
}