@Override protected void _setShort(int index, int value) { memory.putShort(idx(index), (short) value); }
@Override protected byte _getByte(int index) { return memory.get(idx(index)); }
@Override protected short _getShort(int index) { return memory.getShort(idx(index)); }
@Override protected int _getInt(int index) { return memory.getInt(idx(index)); }
@Override protected long _getLong(int index) { return memory.getLong(idx(index)); }
@Override protected void _setByte(int index, int value) { memory.put(idx(index), (byte) value); }
@Override protected void _setMedium(int index, int value) { index = idx(index); memory.put(index, (byte) (value >>> 16)); memory.put(index + 1, (byte) (value >>> 8)); memory.put(index + 2, (byte) value); }
@Override protected void _setMediumLE(int index, int value) { index = idx(index); memory.put(index, (byte) value); memory.put(index + 1, (byte) (value >>> 8)); memory.put(index + 2, (byte) (value >>> 16)); }
@Override protected int _getUnsignedMediumLE(int index) { index = idx(index); return memory.get(index) & 0xff | (memory.get(index + 1) & 0xff) << 8 | (memory.get(index + 2) & 0xff) << 16; }
@Override protected int _getUnsignedMedium(int index) { index = idx(index); return (memory.get(index) & 0xff) << 16 | (memory.get(index + 1) & 0xff) << 8 | memory.get(index + 2) & 0xff; }
@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 void getBytes(int index, byte[] dst, int dstIndex, int length, boolean internal) { checkDstIndex(index, length, dstIndex, dst.length); ByteBuffer tmpBuf; if (internal) { tmpBuf = internalNioBuffer(); } else { tmpBuf = memory.duplicate(); } index = idx(index); tmpBuf.clear().position(index).limit(index + length); tmpBuf.get(dst, dstIndex, length); }
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 ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) { checkSrcIndex(index, length, srcIndex, src.length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); tmpBuf.put(src, srcIndex, length); return this; }
@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 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; } }
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); }