Example usage for io.netty.buffer ByteBufAllocator compositeBuffer

List of usage examples for io.netty.buffer ByteBufAllocator compositeBuffer

Introduction

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

Prototype

CompositeByteBuf compositeBuffer();

Source Link

Document

Allocate a CompositeByteBuf .

Usage

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

License:Apache License

public ArmeriaMessageDeframer(Listener listener, int maxMessageSizeBytes, ByteBufAllocator alloc) {
    this.listener = requireNonNull(listener, "listener");
    this.maxMessageSizeBytes = maxMessageSizeBytes;
    this.alloc = requireNonNull(alloc, "alloc");

    unprocessed = alloc.compositeBuffer();
}

From source file:com.uber.tchannel.codecs.CodecUtils.java

License:Open Source License

public static ByteBuf writeArgs(ByteBufAllocator allocator, ByteBuf header, List<ByteBuf> args) {
    int writableBytes = TFrame.MAX_FRAME_PAYLOAD_LENGTH - header.readableBytes();
    List<ByteBuf> bufs = new ArrayList<>(7);
    bufs.add(header);//from   www.ja  va  2 s.c o  m

    while (!args.isEmpty()) {
        ByteBuf arg = args.get(0);
        int len = writeArg(allocator, arg, writableBytes, bufs);
        writableBytes -= len;
        if (writableBytes <= TFrame.FRAME_SIZE_LENGTH) {
            break;
        }

        if (arg.readableBytes() == 0) {
            args.remove(0);
        }
    }

    CompositeByteBuf comp = allocator.compositeBuffer();
    comp.addComponents(bufs);
    comp.writerIndex(TFrame.MAX_FRAME_PAYLOAD_LENGTH - writableBytes);

    return comp;
}

From source file:org.cloudfoundry.reactor.util.MultipartHttpOutbound.java

License:Apache License

public Mono<Void> done() {
    AsciiString boundary = generateMultipartBoundary();
    ByteBufAllocator allocator = this.outbound.delegate().alloc();

    CompositeByteBuf bodyBuf = allocator.compositeBuffer();
    this.partConsumers
            .forEach(partConsumer -> bodyBuf.addComponent(getPart(allocator, boundary, partConsumer)));
    bodyBuf.addComponent(getCloseDelimiter(allocator, boundary));

    return this.outbound.removeTransferEncodingChunked()
            .addHeader(CONTENT_TYPE, MULTIPART_FORM_DATA.concat(BOUNDARY_PREAMBLE).concat(boundary))
            .addHeader(CONTENT_LENGTH, String.valueOf(bodyBuf.capacity()))
            .sendOne(bodyBuf.writerIndex(bodyBuf.capacity()));
}

From source file:org.cloudfoundry.reactor.util.MultipartHttpOutbound.java

License:Apache License

private static ByteBuf getPart(ByteBufAllocator allocator, AsciiString boundary,
        Consumer<PartHttpOutbound> partConsumer) {
    PartHttpOutbound part = new PartHttpOutbound();
    partConsumer.accept(part);/* w ww.  j a v  a 2 s . co m*/

    CompositeByteBuf body = allocator.compositeBuffer();
    body.addComponent(getDelimiter(allocator, boundary));
    body.addComponent(getHeaders(allocator, part.getHeaders()));
    body.addComponent(getData(allocator, part.getInputStream()));

    return body.writerIndex(body.capacity());
}

From source file:ratpack.stream.bytebuf.ByteBufStreams.java

License:Apache License

/**
 * Reduces the stream to a single composite byte buf.
 *
 * @param publisher the stream/*ww  w  . j a v  a 2  s  .  c  om*/
 * @param alloc the buffer allocator
 * @return the reduced composite buffer
 */
public static Promise<CompositeByteBuf> compose(Publisher<? extends ByteBuf> publisher,
        ByteBufAllocator alloc) {
    return Promise.flatten(() -> {
        CompositeByteBuf seed = alloc.compositeBuffer();
        return Streams.reduce(publisher, seed, (c, b) -> c.addComponent(true, b)).onError(e -> {
            seed.release();
            throw Exceptions.toException(e);
        });
    });
}