/** * @return how many bytes can be safely read, i.e. what is the real capacity of the underlying * data. */ default long safeLimit() { return capacity(); }
/** * @return the actual capacity available before resizing. */ @Override default long realCapacity() { return capacity(); }
@Override public long capacity() { return bytesStore.capacity(); }
@Override public long realCapacity() { return bytesStore.capacity(); }
public SubBytes(@NotNull BytesStore bytesStore) throws IllegalStateException { super(bytesStore); this.start = 0; this.capacity = bytesStore.capacity(); clear(); readLimit(writeLimit()); }
/** * Fill the BytesStore with zeros * * @param start first byte inclusive * @param end last byte exclusive. * @return this. */ @Override @NotNull default B zeroOut(long start, long end) { if (end <= start) return (B) this; if (start < start()) start = start(); if (end > capacity()) end = capacity(); long i = start; try { for (; i < end - 7; i += 8L) writeLong(i, 0L); for (; i < end; i++) writeByte(i, 0); } catch (BufferOverflowException | IllegalArgumentException e) { throw new AssertionError(e); } return (B) this; }
public void msync() throws IOException { if (persisted()) { msync(bsAddress(), bs.capacity()); } }
public long rawCopy(@NotNull BytesStore bytes, long offset, long length) throws BufferOverflowException, IllegalArgumentException { long len = Math.min(writeRemaining(), Math.min(bytes.capacity() - offset, length)); if (len > 0) { writeCheckOffset(writePosition(), len); OS.memory().copyMemory(bytes.addressForRead(offset), addressForWrite(writePosition()), len); writeSkip(len); } return len; }
/** * Copy the data to another BytesStore as long as there is space available in the destination store. * * @param store to copy to * @return how many bytes were copied */ default long copyTo(@NotNull BytesStore store) { long readPos = readPosition(); long writePos = store.writePosition(); long copy = min(readRemaining(), store.capacity()); long i = 0; try { for (; i < copy - 7; i += 8) store.writeLong(writePos + i, readLong(readPos + i)); for (; i < copy; i++) store.writeByte(writePos + i, readByte(readPos + i)); } catch (BufferOverflowException | BufferUnderflowException e) { throw new AssertionError(e); } return copy; }