List of usage examples for io.netty.util.internal EmptyArrays EMPTY_BYTE_BUFFERS
ByteBuffer[] EMPTY_BYTE_BUFFERS
To view the source code for io.netty.util.internal EmptyArrays EMPTY_BYTE_BUFFERS.
Click Source Link
From source file:net.tomp2p.storage.AlternativeCompositeByteBuf.java
License:Apache License
@Override public ByteBuffer[] nioBuffers(int index, int length) { checkIndex(index, length);// w w w. j av a 2s. co m 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()]); }