@Override public int nioBufferCount() { return buf.nioBufferCount(); }
@Override public int nioBufferCount() { return buffer.nioBufferCount(); }
@Override public int nioBufferCount() { return buf.nioBufferCount(); }
@Override public int nioBufferCount() { int size = componentCount; switch (size) { case 0: return 1; case 1: return components[0].buf.nioBufferCount(); default: int count = 0; for (int i = 0; i < size; i++) { count += components[i].buf.nioBufferCount(); } return count; } }
@Override public int nioBufferCount() { return buf.nioBufferCount(); }
static ByteBuffer safeNioBuffer(ByteBuf buffer) { return buffer.nioBufferCount() == 1 ? buffer.internalNioBuffer(buffer.readerIndex(), buffer.readableBytes()) : buffer.nioBuffer(); } }
/** * Checks if the specified buffer is a direct buffer and is composed of a single NIO buffer. * (We check this because otherwise we need to make it a non-composite buffer.) */ private static boolean isSingleDirectBuffer(ByteBuf buf) { return buf.isDirect() && buf.nioBufferCount() == 1; }
@Override public int nioBufferCount() { return unwrap().nioBufferCount(); }
@Override public int nioBufferCount() { return unwrap().nioBufferCount(); }
@Override public int nioBufferCount() { return unwrap().nioBufferCount(); }
static ByteBuffer safeNioBuffer(ByteBuf buffer) { return buffer.nioBufferCount() == 1 ? buffer.internalNioBuffer(buffer.readerIndex(), buffer.readableBytes()) : buffer.nioBuffer(); } }
/** * Checks if the specified buffer is a direct buffer and is composed of a single NIO buffer. * (We check this because otherwise we need to make it a non-composite buffer.) */ private static boolean isSingleDirectBuffer(ByteBuf buf) { return buf.isDirect() && buf.nioBufferCount() == 1; }
@Override public int nioBufferCount() { return unwrap().nioBufferCount(); }
@Override public int nioBufferCount() { return unwrap().nioBufferCount(); }
@Override public ByteBuffer nioBuffer(int index, int length) { checkIndex(index, length); if (buffers.length == 1) { ByteBuf buf = buffer(0); if (buf.nioBufferCount() == 1) { return buf.nioBuffer(index, length); } } ByteBuffer merged = ByteBuffer.allocate(length).order(order()); ByteBuffer[] buffers = nioBuffers(index, length); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < buffers.length; i++) { merged.put(buffers[i]); } merged.flip(); return merged; }
@Override public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) { checkSrcIndex(index, length, srcIndex, src.capacity()); if (src.nioBufferCount() > 0) { for (ByteBuffer bb: src.nioBuffers(srcIndex, length)) { int bbLen = bb.remaining(); setBytes(index, bb); index += bbLen; } } else { src.getBytes(srcIndex, this, index, length); } return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { checkDstIndex(index, length, dstIndex, dst.capacity()); if (dst.hasArray()) { getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length); } else if (dst.nioBufferCount() > 0) { for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) { int bbLen = bb.remaining(); getBytes(index, bb); index += bbLen; } } else { dst.setBytes(dstIndex, this, index, length); } return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { checkDstIndex(index, length, dstIndex, dst.capacity()); if (dst.hasArray()) { getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length); } else if (dst.nioBufferCount() > 0) { for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) { int bbLen = bb.remaining(); getBytes(index, bb); index += bbLen; } } else { dst.setBytes(dstIndex, this, index, length); } return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { checkDstIndex(index, length, dstIndex, dst.capacity()); if (dst.hasArray()) { getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length); } else if (dst.nioBufferCount() > 0) { for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) { int bbLen = bb.remaining(); getBytes(index, bb); index += bbLen; } } else { dst.setBytes(dstIndex, this, index, length); } return this; }
@Override public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) { checkSrcIndex(index, length, srcIndex, src.capacity()); if (src.hasArray()) { setBytes(index, src.array(), src.arrayOffset() + srcIndex, length); } else if (src.nioBufferCount() > 0) { for (ByteBuffer bb: src.nioBuffers(srcIndex, length)) { int bbLen = bb.remaining(); setBytes(index, bb); index += bbLen; } } else { src.getBytes(srcIndex, this, index, length); } return this; }