private static DirectByteBuffer copy(DirectByteBuffer other, int markOfOther, boolean isReadOnly) { DirectByteBuffer buf = new DirectByteBuffer(other.block, other.capacity(), other.offset, isReadOnly, other.mapMode); buf.limit = other.limit; buf.position = other.position(); buf.mark = markOfOther; return buf; }
@Override public DoubleBuffer get(double[] dst, int dstOffset, int doubleCount) { byteBuffer.limit(limit * SizeOf.DOUBLE); byteBuffer.position(position * SizeOf.DOUBLE); if (byteBuffer instanceof DirectByteBuffer) { ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, doubleCount); } else { ((ByteArrayBuffer) byteBuffer).get(dst, dstOffset, doubleCount); } this.position += doubleCount; return this; }
@Override public ByteBuffer slice() { return new DirectByteBuffer(block, remaining(), offset + position, isReadOnly, mapMode); }
static DirectReadWriteByteBuffer copy (DirectByteBuffer other, int markOfOther) { DirectReadWriteByteBuffer buf = new DirectReadWriteByteBuffer(other.byteArray.buffer(), other.capacity(), other.byteArray.byteOffset()); buf.limit = other.limit(); buf.position = other.position(); buf.mark = markOfOther; buf.order(other.order()); return buf; }
public final ByteBuffer get (byte[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = 0; i < len; i++) { dest[i + off] = get(position + i); } position += len; return this; }
@Override public ByteBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } Memory.memmove(this, 0, this, position, remaining()); position = limit - position; limit = capacity; mark = UNSET_MARK; return this; }
final void get(char[] dst, int dstOffset, int charCount) { int byteCount = checkGetBounds(SizeOf.CHAR, dst.length, dstOffset, charCount); this.block.peekCharArray(offset + position, dst, dstOffset, charCount, order.needsSwap); position += byteCount; }
@Override public final float getFloat(int index) { checkIndex(index, SizeOf.FLOAT); return Float.intBitsToFloat(this.block.peekInt(offset + index, order)); }
final void put(int[] src, int srcOffset, int intCount) { int byteCount = checkPutBounds(SizeOf.INT, src.length, srcOffset, intCount); this.block.pokeIntArray(offset + position, src, srcOffset, intCount, order.needsSwap); position += byteCount; }
@Override public ByteBuffer duplicate() { return copy(this, mark, isReadOnly); }
public static void freeDirectBuffer(ByteBuffer buffer) { if (buffer == null) { return; } ((DirectByteBuffer) buffer).free(); }
/** * Creates a direct byte buffer based on a newly allocated memory block. * * @param capacity * the capacity of the new buffer * @return the created byte buffer. * @throws IllegalArgumentException * if {@code capacity < 0}. */ public static ByteBuffer allocateDirect(int capacity) { if (capacity < 0) { throw new IllegalArgumentException("capacity < 0: " + capacity); } return new DirectByteBuffer(MemoryBlock.allocate(capacity), capacity, 0, false, null); }
static DirectReadWriteByteBuffer copy (DirectByteBuffer other, int markOfOther) { DirectReadWriteByteBuffer buf = new DirectReadWriteByteBuffer(other.byteArray.buffer(), other.capacity(), other.byteArray.byteOffset()); buf.limit = other.limit(); buf.position = other.position(); buf.mark = markOfOther; buf.order(other.order()); return buf; }
public final ByteBuffer get (byte[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int i = 0; i < len; i++) { dest[i + off] = get(position + i); } position += len; return this; }
@Override public ByteBuffer compact() { if (isReadOnly) { throw new ReadOnlyBufferException(); } Memory.memmove(this, 0, this, position, remaining()); position = limit - position; limit = capacity; mark = UNSET_MARK; return this; }
final void get(short[] dst, int dstOffset, int shortCount) { int byteCount = checkGetBounds(SizeOf.SHORT, dst.length, dstOffset, shortCount); this.block.peekShortArray(offset + position, dst, dstOffset, shortCount, order.needsSwap); position += byteCount; }