@Override public MappedNativeBytes bytes(long offset, long length) { long sliceStart = start + offset; assert sliceStart >= start && sliceStart < capacity; long sliceEnd = sliceStart + length; assert sliceEnd > sliceStart && sliceEnd <= capacity; return new MappedNativeBytes(objectSerializer(), sliceStart, sliceEnd, refCount, mappedFile, isSingleThreaded); }
void offsetChecks(long offset, long len) { assert actualOffsetChecks(offset, len); }
void positionChecks(long positionAddr) { assert actualPositionChecks(positionAddr); }
@Override public MappedNativeBytes position(long position) { if (position < 0 || position > limit()) throw new IndexOutOfBoundsException("position: " + position + " limit: " + limit()); positionAddr(start + position); return this; }
@Override public long readVolatileLong() { long l = getChronicleUnsafe().getLongVolatile(null, position); addPosition(8); return l; }
@Override public void writeByte(long offset, int b) { offsetChecks(offset, 1L); getChronicleUnsafe().putByte(start + offset, (byte) b); }
@Override public void readFully(@NotNull byte[] b, int off, int len) { checkArrayOffs(b.length, off, len); long left = remaining(); if (left < len) throw new IllegalStateException(new EOFException()); getChronicleUnsafe().copyMemory(null, position, b, BYTES_OFFSET + off, len); addPosition(len); }
@Override public void writeChar(int v) { positionChecks(position + 2L); getChronicleUnsafe().putChar(position, (char) v); position += 2L; }
@Override public void write(byte[] bytes, int off, int len) { if (off < 0 || off + len > bytes.length || len > remaining()) throw new IllegalArgumentException(); getChronicleUnsafe().copyMemory(bytes, BYTES_OFFSET + off, null, position, len); addPosition(len); }
@Override public void write(long offset, @NotNull byte[] bytes) { if (offset < 0 || offset + bytes.length > capacity()) throw new IllegalArgumentException(); getChronicleUnsafe().copyMemory(bytes, BYTES_OFFSET, null, start + offset, bytes.length); addPosition(bytes.length); }
@Override public void write(RandomDataInput bytes, long position, long length) { if (length > remaining()) throw new IllegalArgumentException("Attempt to write " + length + " bytes with " + remaining() + " remaining"); if (bytes instanceof MappedNativeBytes) { getChronicleUnsafe().copyMemory(((MappedNativeBytes) bytes).start + position, this.position, length); skip(length); } else { super.write(bytes, position, length); } }
@Override public Bytes zeroOut() { clear(); getChronicleUnsafe().setMemory(start, capacity(), (byte) 0); return this; }
@Override public void write(int b) { getChronicleUnsafe().putByte(position, (byte) b); incrementPositionAddr(1); }
@Override public Bytes zeroOut(long start, long end) { if (start < 0 || end > limit()) throw new IllegalArgumentException("start: " + start + ", end: " + end); if (start >= end) return this; getChronicleUnsafe().setMemory(this.start + start, end - start, (byte) 0); return this; }
@Override public void write(long offset, byte[] bytes, int off, int len) { if (offset < 0 || off + len > bytes.length || offset + len > capacity()) throw new IllegalArgumentException(); getChronicleUnsafe().copyMemory(bytes, BYTES_OFFSET + off, null, start + offset, len); }
@Override public void readFully(long offset, byte[] bytes, int off, int len) { checkArrayOffs(bytes.length, off, len); getChronicleUnsafe().copyMemory(null, start + offset, bytes, BYTES_OFFSET + off, len); }
@Override public Bytes load() { ChronicleUnsafe unsafe = getChronicleUnsafe(); int pageSize = unsafe.pageSize(); for (long addr = start; addr < capacity; addr += pageSize) unsafe.getByte(addr); return this; }
@Override public double readDouble() { double d = getChronicleUnsafe().getDouble(position); addPosition(8); return d; }