public MappedBytes write8bit(@Nullable BytesStore bs) throws BufferOverflowException { if (bs == null) { writeStopBit(-1); } else { long offset = bs.readPosition(); long readRemaining = Math.min(writeRemaining(), bs.readLimit() - offset); writeStopBit(readRemaining); write(bs, offset, readRemaining); } return this; } }
@NotNull @Override public Bytes<Void> write(@NotNull BytesStore bytes, long offset, long length) throws BufferUnderflowException, BufferOverflowException { assert singleThreadedAccess(); if (length == 8) writeLong(bytes.readLong(offset)); else if (bytes.isDirectMemory() && length <= Math.min(writeRemaining(), safeCopySize())) rawCopy(bytes, offset, length); else if (length > 0) BytesInternal.writeFully(bytes, offset, length, this); return this; }
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; }