@NotNull @Override public Bytes<Void> readPositionRemaining(long position, long remaining) throws BufferUnderflowException { long limit = position + remaining; acquireNextByteStore(position, true); if (writeLimit < limit) writeLimit(limit); boolean debug = false; assert debug = true; if (debug) readLimit(limit); else uncheckedWritePosition(limit); return readPosition(position); }
public MappedBytes write(long offsetInRDO, byte[] bytes, int offset, int length) { long wp = offsetInRDO; if ((length + offset) > bytes.length) throw new ArrayIndexOutOfBoundsException("bytes.length=" + bytes.length + ", " + "length=" + length + ", offset=" + offset); if (length > writeRemaining()) throw new DecoratedBufferOverflowException( String.format("write failed. Length: %d > writeRemaining: %d", length, writeRemaining())); int remaining = length; acquireNextByteStore(wp, false); while (remaining > 0) { long safeCopySize = copySize(wp); if (safeCopySize + mappedFile.overlapSize() >= remaining) { bytesStore.write(wp, bytes, offset, remaining); return this; } bytesStore.write(wp, bytes, offset, (int) safeCopySize); offset += safeCopySize; wp += safeCopySize; remaining -= safeCopySize; // move to the next chunk acquireNextByteStore0(wp, false); } return this; }
public MappedBytes write(long writeOffset, RandomDataInput bytes, long readOffset, long length) throws BufferOverflowException, BufferUnderflowException { long wp = writeOffset; if (length > writeRemaining()) throw new DecoratedBufferOverflowException( String.format("write failed. Length: %d > writeRemaining: %d", length, writeRemaining())); long remaining = length; acquireNextByteStore(wp, false); while (remaining > 0) { long safeCopySize = copySize(wp); if (safeCopySize + mappedFile.overlapSize() >= remaining) { bytesStore.write(wp, bytes, readOffset, remaining); return this; } bytesStore.write(wp, bytes, readOffset, safeCopySize); readOffset += safeCopySize; wp += safeCopySize; remaining -= safeCopySize; // move to the next chunk acquireNextByteStore0(wp, false); } return this; }
public long rawCopy(@NotNull BytesStore bytes, long offset, long length) throws BufferOverflowException, BufferUnderflowException { assert length < safeCopySize(); this.acquireNextByteStore(writePosition(), false); long len = Math.min(writeRemaining(), Math.min(bytes.readRemaining(), length)); if (len > 0) { OS.memory().copyMemory(bytes.addressForRead(offset), addressForWrite(writePosition()), len); uncheckedWritePosition(writePosition() + len); } return len; }