Example usage for io.netty.buffer ByteBuf nioBuffers

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

Introduction

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

Prototype

public abstract ByteBuffer[] nioBuffers();

Source Link

Document

Exposes this buffer's readable bytes as an NIO ByteBuffer 's.

Usage

From source file:org.sfs.io.AsyncFileWriterImpl.java

License:Apache License

private AsyncFileWriterImpl doWrite(Buffer buffer, long position, Handler<AsyncResult<Void>> handler) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkArgument(position >= 0, "position must be >= 0");
    Handler<AsyncResult<Void>> wrapped = ar -> {
        if (ar.succeeded()) {
            if (handler != null) {
                handler.handle(ar);//from   ww w .j  av a 2 s  . co m
            }
        } else {
            if (handler != null) {
                handler.handle(ar);
            } else {
                handleException(ar.cause());
            }
        }
    };
    ByteBuf buf = buffer.getByteBuf();
    if (buf.nioBufferCount() > 1) {
        doWrite(buf.nioBuffers(), position, wrapped);
    } else {
        ByteBuffer bb = buf.nioBuffer();
        doWrite(bb, position, bb.limit(), wrapped);
    }
    return this;
}