@Override public ByteBuffer nioBuffer(int index, int length) { checkIndex(index, length); index = idx(index); return ((ByteBuffer) memory.duplicate().position(index).limit(index + length)).slice(); }
private void getBytes(int index, ByteBuffer dst, boolean internal) { checkIndex(index, dst.remaining()); ByteBuffer tmpBuf; if (internal) { tmpBuf = internalNioBuffer(); } else { tmpBuf = memory.duplicate(); } index = idx(index); tmpBuf.clear().position(index).limit(index + dst.remaining()); dst.put(tmpBuf); }
@Override public ByteBuf setBytes(int index, ByteBuffer src) { checkIndex(index, src.remaining()); ByteBuffer tmpBuf = internalNioBuffer(); if (src == tmpBuf) { src = src.duplicate(); } index = idx(index); tmpBuf.clear().position(index).limit(index + src.remaining()); tmpBuf.put(src); return this; }
private int getBytes(int index, FileChannel out, long position, int length, boolean internal) throws IOException { checkIndex(index, length); if (length == 0) { return 0; } ByteBuffer tmpBuf = internal ? internalNioBuffer() : memory.duplicate(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); return out.write(tmpBuf, position); }
@Override public int setBytes(int index, FileChannel in, long position, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf, position); } catch (ClosedChannelException ignored) { return -1; } }
@Override public ByteBuffer internalNioBuffer(int index, int length) { checkIndex(index, length); index = idx(index); return (ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length); }
@Override public ByteBuffer nioBuffer(int index, int length) { checkIndex(index, length); index = idx(index); return ((ByteBuffer) memory.duplicate().position(index).limit(index + length)).slice(); }
@Override public ByteBuf setBytes(int index, ByteBuffer src) { checkIndex(index, src.remaining()); ByteBuffer tmpBuf = internalNioBuffer(); if (src == tmpBuf) { src = src.duplicate(); } index = idx(index); tmpBuf.clear().position(index).limit(index + src.remaining()); tmpBuf.put(src); return this; }
private void getBytes(int index, ByteBuffer dst, boolean internal) { checkIndex(index, dst.remaining()); ByteBuffer tmpBuf; if (internal) { tmpBuf = internalNioBuffer(); } else { tmpBuf = memory.duplicate(); } index = idx(index); tmpBuf.clear().position(index).limit(index + dst.remaining()); dst.put(tmpBuf); }
private int getBytes(int index, FileChannel out, long position, int length, boolean internal) throws IOException { checkIndex(index, length); if (length == 0) { return 0; } ByteBuffer tmpBuf = internal ? internalNioBuffer() : memory.duplicate(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); return out.write(tmpBuf, position); }
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
@Override public int setBytes(int index, InputStream in, int length) throws IOException { checkIndex(index, length); byte[] tmp = ByteBufUtil.threadLocalTempArray(length); int readBytes = in.read(tmp, 0, length); if (readBytes <= 0) { return readBytes; } ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(idx(index)); tmpBuf.put(tmp, 0, readBytes); return readBytes; }
@Override public int setBytes(int index, FileChannel in, long position, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf, position); } catch (ClosedChannelException ignored) { return -1; } }
@Override public 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); if (length == 0) { return 0; } ByteBuffer tmpBuf; if (internal) { tmpBuf = internalNioBuffer(); } else { tmpBuf = memory.duplicate(); } index = idx(index); tmpBuf.clear().position(index).limit(index + length); return out.write(tmpBuf); }
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
@Override public ByteBuf copy(int index, int length) { checkIndex(index, length); ByteBuf copy = alloc().directBuffer(length, maxCapacity()); copy.writeBytes(this, index, length); return copy; }
@Override public ByteBuf copy(int index, int length) { checkIndex(index, length); ByteBuf copy = alloc().directBuffer(length, maxCapacity()); copy.writeBytes(this, index, length); return copy; }
private void getBytes(int index, OutputStream out, int length, boolean internal) throws IOException { checkIndex(index, length); if (length == 0) { return; } ByteBufUtil.readBytes(alloc(), internal ? internalNioBuffer() : memory.duplicate(), idx(index), length, out); }
private void getBytes(int index, OutputStream out, int length, boolean internal) throws IOException { checkIndex(index, length); if (length == 0) { return; } ByteBufUtil.readBytes(alloc(), internal ? internalNioBuffer() : memory.duplicate(), idx(index), length, out); }