List of usage examples for io.netty.buffer ByteBuf nioBuffers
public abstract ByteBuffer[] nioBuffers(int index, int length);
From source file:net.tomp2p.storage.AlternativeCompositeByteBuf.java
License:Apache License
@Override public ByteBuffer[] nioBuffers(int index, int length) { checkIndex(index, length);//from w w w.jav a 2s.c om if (length == 0) { return EmptyArrays.EMPTY_BYTE_BUFFERS; } List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(components.size()); int i = findIndex(index); while (length > 0) { Component c = components.get(i); ByteBuf s = c.buf; int adjustment = c.offset; int localLength = Math.min(length, s.readableBytes() - (index - adjustment)); switch (s.nioBufferCount()) { case 0: throw new UnsupportedOperationException(); case 1: buffers.add(s.nioBuffer(index - adjustment, localLength)); break; default: Collections.addAll(buffers, s.nioBuffers(index - adjustment, localLength)); } index += localLength; length -= localLength; i++; } return buffers.toArray(new ByteBuffer[buffers.size()]); }