@Override protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) { return buffer.slice(index, length); } }
@Override public ByteBuf slice() { return buf.slice(); }
@Override public ByteBuf slice(int index, int length) { return buf.slice(index, length); }
/** * Creates a new big-endian buffer which wraps the sub-region of the * specified {@code array}. A modification on the specified array's * content will be visible to the returned buffer. */ public static ByteBuf wrappedBuffer(byte[] array, int offset, int length) { if (length == 0) { return EMPTY_BUFFER; } if (offset == 0 && length == array.length) { return wrappedBuffer(array); } return wrappedBuffer(array).slice(offset, length); }
/** * Creates a new buffer which wraps the specified buffer's readable bytes. * A modification on the specified buffer's content will be visible to the * returned buffer. * @param buffer The buffer to wrap. Reference count ownership of this variable is transferred to this method. * @return The readable portion of the {@code buffer}, or an empty buffer if there is no readable portion. * The caller is responsible for releasing this buffer. */ public static ByteBuf wrappedBuffer(ByteBuf buffer) { if (buffer.isReadable()) { return buffer.slice(); } else { buffer.release(); return EMPTY_BUFFER; } }
@Override public NettyDataBuffer slice(int index, int length) { ByteBuf slice = this.byteBuf.slice(index, length); return new NettyDataBuffer(slice, this.dataBufferFactory); }
@Override public ByteBuf slice(int index, int length) { checkIndex(index, length); return buffer.slice(index, length); }
@Override public ByteBuf retainedSlice(int index, int length) { checkIndex(index, length); return buffer.slice(index, length); }
@Override public ByteBuf slice() { return new UnreleasableByteBuf(buf.slice()); }
@Override public ByteBuf slice(int index, int length) { return new UnreleasableByteBuf(buf.slice(index, length)); }
@Override public ByteBuf slice() { return buf.slice().order(order); }
@Override public ByteBuf slice(int index, int length) { return unwrap().slice(index, length); }
@Override public ByteBuf slice(int index, int length) { return buf.slice(index, length).order(order); }
@Override public ByteBuf slice(int index, int length) { return Unpooled.unmodifiableBuffer(unwrap().slice(index, length)); }
ByteBuf slice() { return slice != null ? slice : (slice = buf.slice(idx(offset), length())); }
private static ByteBuf paddedByteBuf(int padding, byte[] bytes) { byte[] data = new byte[padding + bytes.length]; System.arraycopy(bytes, 0, data, padding, bytes.length); return Unpooled.copiedBuffer(data).slice(padding, bytes.length); }
ByteBuf decode(ByteBuf src, int off, int len, ByteBufAllocator allocator, Base64Dialect dialect) { dest = allocator.buffer(decodedBufferSize(len)).order(src.order()); // Upper limit on size of output decodabet = decodabet(dialect); try { src.forEachByte(off, len, this); return dest.slice(0, outBuffPosn); } catch (Throwable cause) { dest.release(); PlatformDependent.throwException(cause); return null; } }
@Override public ByteBuf slice(int index, int length) { checkIndex0(index, length); return unwrap().slice(idx(index), length); }
@Override public ByteBuf slice(int index, int length) { checkIndex0(index, length); return unwrap().slice(idx(index), length); }
@Test public void testLength2() throws Exception { byte[] bytes = TestUtils.randomByteArray(100); assertEquals(90, Buffer.buffer(Unpooled.copiedBuffer(bytes).slice(10, 90)).length()); }