Add nioBuffers() and nioBuffers(..) method which will be used to support gathering writes for the AIO transport. See #492

This commit is contained in:
norman 2012-08-07 15:39:39 +02:00
parent 0334333c82
commit f7e0366bae
2 changed files with 36 additions and 1 deletions

View File

@ -15,6 +15,7 @@
*/
package io.netty.buffer;
import java.nio.ByteBuffer;
import java.util.List;
public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
@ -47,4 +48,32 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* Same with {@link #slice(int, int)} except that this method returns a list.
*/
List<ByteBuf> decompose(int offset, int length);
/**
* Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}'s. The returned buffer
* shares the content with this buffer, while changing the position and limit of the returned
* NIO buffer does not affect the indexes and marks of this buffer. This method does not
* modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the
* returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic
* buffer and it adjusted its capacity.
*
*
* @throws UnsupportedOperationException
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
*/
ByteBuffer[] nioBuffers();
/**
* Exposes this buffer's bytes as an NIO {@link ByteBuffer}'s for the specified offset and length
* The returned buffer shares the content with this buffer, while changing the position and limit
* of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does
* not modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the
* returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic
* buffer and it adjusted its capacity.
*
*
* @throws UnsupportedOperationException
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
*/
ByteBuffer[] nioBuffers(int offset, int length);
}

View File

@ -1011,7 +1011,8 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
return merged;
}
private ByteBuffer[] nioBuffers(int index, int length) {
@Override
public ByteBuffer[] nioBuffers(int index, int length) {
int componentId = toComponentIndex(index);
if (index + length > capacity()) {
throw new IndexOutOfBoundsException("Too many bytes to convert - Needs"
@ -1224,4 +1225,9 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
}
}
}
@Override
public ByteBuffer[] nioBuffers() {
return nioBuffers(readerIndex(), readableBytes());
}
}