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.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

private static DnsRecord newMappedAddressRecord(String name, String ipV4Addr) {
    final ByteBuf content = Unpooled.buffer();
    content.writeZero(10);/*from   w w  w  .jav a 2 s  .  com*/
    content.writeShort(0xFFFF);
    content.writeBytes(NetUtil.createByteArrayFromIpAddressString(ipV4Addr));
    return new DefaultDnsRawRecord(name, AAAA, 60, content);
}

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

License:Apache License

private static DnsRecord newCnameRecord(String name, String actualName) {
    final ByteBuf content = Unpooled.buffer();
    DnsNameEncoder.encodeName(actualName, content);
    return new DefaultDnsRawRecord(name, CNAME, 60, content);
}

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

License:Apache License

private static DnsRecord newSrvRecord(String hostname, int weight, int port, String target) {
    final ByteBuf content = Unpooled.buffer();
    content.writeShort(1); // priority unused
    content.writeShort(weight);//from  w ww  .j  a  va 2s .  co m
    content.writeShort(port);
    DnsNameEncoder.encodeName(target, content);
    return new DefaultDnsRawRecord(hostname, SRV, 60, content);
}

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

License:Apache License

private static DnsRecord newTxtRecord(String hostname, String text) {
    final ByteBuf content = Unpooled.buffer();
    content.writeByte(text.length());//from   w ww. jav  a2s .c  o m
    content.writeBytes(text.getBytes(StandardCharsets.US_ASCII));
    return new DefaultDnsRawRecord(hostname, TXT, 60, content);
}

From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java

License:Apache License

public static ByteBuf protoByteBuf(MessageLite msg) {
    ByteBuf buf = Unpooled.buffer();
    try (ByteBufOutputStream os = new ByteBufOutputStream(buf)) {
        msg.writeTo(os);/*from   w  w w  .  j av  a 2 s  .c  om*/
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return buf;
}

From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java

License:Apache License

public static byte[] uncompressedFrame(ByteBuf proto) {
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(0);// w  w w.  j a va  2 s. c om
    buf.writeInt(proto.readableBytes());
    buf.writeBytes(proto);
    proto.release();
    byte[] result = ByteBufUtil.getBytes(buf);
    buf.release();
    return result;
}

From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java

License:Apache License

public static byte[] compressedFrame(ByteBuf uncompressed) {
    ByteBuf compressed = Unpooled.buffer();
    try (ByteBufInputStream is = new ByteBufInputStream(uncompressed, true);
            GZIPOutputStream os = new GZIPOutputStream(new ByteBufOutputStream(compressed))) {
        ByteStreams.copy(is, os);//from   w ww .  j  ava2s .  c  o m
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(1);
    buf.writeInt(compressed.readableBytes());
    buf.writeBytes(compressed);
    compressed.release();
    byte[] result = ByteBufUtil.getBytes(buf);
    buf.release();
    return result;
}

From source file:com.linecorp.armeria.server.encoding.HttpEncodedResponseTest.java

License:Apache License

@Test
public void testLeak() {
    final ByteBuf buf = Unpooled.buffer();
    buf.writeCharSequence("foo", StandardCharsets.UTF_8);

    final HttpResponse orig = HttpResponse.of(AggregatedHttpMessage.of(HttpStatus.OK,
            MediaType.PLAIN_TEXT_UTF_8, new ByteBufHttpData(buf, true)));
    final HttpEncodedResponse encoded = new HttpEncodedResponse(orig, HttpEncodingType.DEFLATE,
            mediaType -> true, 1);//  ww w.j  av  a 2 s.  c  o  m

    // Drain the stream.
    encoded.subscribe(NoopSubscriber.get(), ImmediateEventExecutor.INSTANCE);

    // 'buf' should be released.
    assertThat(buf.refCnt()).isZero();
}

From source file:com.linecorp.armeria.server.grpc.ArmeriaGrpcServerStreamTest.java

License:Apache License

private static byte[] compressionFrame(byte[] data) {
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(0);//from   w  w  w . j a v  a  2  s.  co  m
    buf.writeInt(data.length);
    buf.writeBytes(data);
    return ByteBufUtil.getBytes(buf);
}

From source file:com.mastfrog.scamper.password.crypto.EncryptingCodecTest.java

License:Open Source License

private ByteBuf bufFor(String data) throws UnsupportedEncodingException {
    ByteBuf buf = Unpooled.buffer();
    buf.writeBytes(data.getBytes("UTF-8"));
    return buf;//  w  ww  .java 2 s. c  o  m
}