Example usage for io.netty.buffer ByteBufAllocator directBuffer

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

Introduction

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

Prototype

ByteBuf directBuffer(int initialCapacity);

Source Link

Document

Allocate a direct ByteBuf with the given initial capacity.

Usage

From source file:divconq.net.ssl.SslHandler.java

License:Apache License

private ByteBuf allocate(ChannelHandlerContext ctx, int capacity) {
    ByteBufAllocator alloc = ctx.alloc();
    if (wantsDirectBuffer) {
        return alloc.directBuffer(capacity);
    } else {/*from ww w .  j a  v a  2 s .  co  m*/
        return alloc.buffer(capacity);
    }
}

From source file:org.apache.bookkeeper.bookie.BufferedChannel.java

License:Apache License

public BufferedChannel(ByteBufAllocator allocator, FileChannel fc, int writeCapacity, int readCapacity,
        long unpersistedBytesBound) throws IOException {
    super(fc, readCapacity);
    this.writeCapacity = writeCapacity;
    this.position = new AtomicLong(fc.position());
    this.writeBufferStartPosition.set(position.get());
    this.writeBuffer = allocator.directBuffer(writeCapacity);
    this.unpersistedBytes = new AtomicLong(0);
    this.unpersistedBytesBound = unpersistedBytesBound;
    this.doRegularFlushes = unpersistedBytesBound > 0;
}

From source file:org.apache.flink.runtime.io.network.netty.NettyMessage.java

License:Apache License

private static ByteBuf allocateBuffer(ByteBufAllocator allocator, byte id, int length) {
    final ByteBuf buffer = length != 0 ? allocator.directBuffer(HEADER_LENGTH + length)
            : allocator.directBuffer();/*from w  ww .  jav a  2 s  .c  om*/
    buffer.writeInt(HEADER_LENGTH + length);
    buffer.writeInt(MAGIC_NUMBER);
    buffer.writeByte(id);

    return buffer;
}

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

License:Apache License

private static ByteBuf getCloseDelimiter(ByteBufAllocator allocator, AsciiString boundary) {
    AsciiString s = DOUBLE_DASH.concat(boundary).concat(DOUBLE_DASH);
    return allocator.directBuffer(s.length()).writeBytes(s.toByteArray());
}

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

License:Apache License

private static ByteBuf getData(ByteBufAllocator allocator, InputStream inputStream) {
    try (InputStream in = inputStream) {
        ByteBuf dataBuf = allocator.directBuffer(CRLF.length() + inputStream.available() + CRLF.length());

        dataBuf.writeBytes(CRLF.toByteArray());
        dataBuf.writeBytes(in, in.available());
        dataBuf.writeBytes(CRLF.toByteArray());

        return dataBuf;
    } catch (IOException e) {
        throw Exceptions.propagate(e);
    }/*from www  . j  a  va 2s . co  m*/
}

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

License:Apache License

private static ByteBuf getDelimiter(ByteBufAllocator allocator, AsciiString boundary) {
    AsciiString s = DOUBLE_DASH.concat(boundary).concat(CRLF);
    return allocator.directBuffer(s.length()).writeBytes(s.toByteArray());
}

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

License:Apache License

private static ByteBuf getHeaders(ByteBufAllocator allocator, HttpHeaders headers) {
    AsciiString s = AsciiString.EMPTY_STRING;

    for (Map.Entry<String, String> entry : headers) {
        s = s.concat(new AsciiString(entry.getKey())).concat(HEADER_DELIMITER).concat(entry.getValue())
                .concat(CRLF);/*from  ww w . j a  va2  s  . co  m*/
    }

    return allocator.directBuffer(s.length()).writeBytes(s.toByteArray());
}