@Override public final ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) { checkDstIndex(index, length, dstIndex, dst.length); System.arraycopy(memory, idx(index), dst, dstIndex, length); return this; }
@Override public final ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) { checkSrcIndex(index, length, srcIndex, src.length); System.arraycopy(src, srcIndex, memory, idx(index), length); return this; }
@Override public final ByteBuf getBytes(int index, ByteBuffer dst) { checkIndex(index, dst.remaining()); dst.put(memory, idx(index), dst.remaining()); return this; }
@Override public final int setBytes(int index, InputStream in, int length) throws IOException { checkIndex(index, length); return in.read(memory, idx(index), length); }
@Override public final ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { checkIndex(index, length); out.write(memory, idx(index), length); return this; }
@Override public final ByteBuf setBytes(int index, ByteBuffer src) { int length = src.remaining(); checkIndex(index, length); src.get(memory, idx(index), length); return this; }
@Override public final ByteBuffer nioBuffer(int index, int length) { checkIndex(index, length); index = idx(index); ByteBuffer buf = ByteBuffer.wrap(memory, index, length); return buf.slice(); }
@Override protected int _getUnsignedMediumLE(int index) { return HeapByteBufUtil.getUnsignedMediumLE(memory, idx(index)); }
@Override protected long _getLongLE(int index) { return HeapByteBufUtil.getLongLE(memory, idx(index)); }
@Override protected int _getUnsignedMedium(int index) { return HeapByteBufUtil.getUnsignedMedium(memory, idx(index)); }
@Override protected void _setInt(int index, int value) { HeapByteBufUtil.setInt(memory, idx(index), value); }
@Override protected short _getShort(int index) { return HeapByteBufUtil.getShort(memory, idx(index)); }
private int getBytes(int index, FileChannel out, long position, int length, boolean internal) throws IOException { checkIndex(index, length); index = idx(index); ByteBuffer tmpBuf = internal ? internalNioBuffer() : ByteBuffer.wrap(memory); return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length), position); }
@Override public final int setBytes(int index, FileChannel in, long position, int length) throws IOException { checkIndex(index, length); index = idx(index); try { return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length), position); } catch (ClosedChannelException ignored) { return -1; } }
@Override public final ByteBuffer internalNioBuffer(int index, int length) { checkIndex(index, length); index = idx(index); return (ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length); }
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException { checkIndex(index, length); index = idx(index); ByteBuffer tmpBuf; if (internal) { tmpBuf = internalNioBuffer(); } else { tmpBuf = ByteBuffer.wrap(memory); } return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length)); }
@Override public final int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); index = idx(index); try { return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)); } catch (ClosedChannelException ignored) { return -1; } }
@Override public final ByteBuf copy(int index, int length) { checkIndex(index, length); ByteBuf copy = alloc().heapBuffer(length, maxCapacity()); copy.writeBytes(memory, idx(index), length); return copy; }
@Override public final ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) { checkSrcIndex(index, length, srcIndex, src.capacity()); if (src.hasMemoryAddress()) { PlatformDependent.copyMemory(src.memoryAddress() + srcIndex, memory, idx(index), length); } else if (src.hasArray()) { setBytes(index, src.array(), src.arrayOffset() + srcIndex, length); } else { src.getBytes(srcIndex, memory, idx(index), length); } return this; }
@Override public final ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { checkDstIndex(index, length, dstIndex, dst.capacity()); if (dst.hasMemoryAddress()) { PlatformDependent.copyMemory(memory, idx(index), dst.memoryAddress() + dstIndex, length); } else if (dst.hasArray()) { getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length); } else { dst.setBytes(dstIndex, memory, idx(index), length); } return this; }