@Override default long readLong(S handle, long offset) { return handle.readLong(offset); }
@Override default long readLong(S handle, long offset) { return handle.readLong(offset); }
@Override public boolean equivalent(RandomDataInput source, long sourceOffset) { return source.readLong(sourceOffset) == instance; }
@Override public boolean equivalent(RandomDataInput source, long sourceOffset) { return source.readLong(sourceOffset) == Double.doubleToRawLongBits(instance); }
@NotNull @Override public Bytes<Underlying> write(@NotNull RandomDataInput bytes, long offset, long length) throws BufferOverflowException, IllegalArgumentException { if (length == 8) { writeLong(bytes.readLong(offset)); } else { super.write(bytes, offset, length); } return this; }
/** * Copy data from this RandomDataInput to the ByteBuffer. The minimum of {@link #readRemaining()} and * {@link ByteBuffer#remaining()}. Starting from {@link #start()} in this RandomDataInput and from {@link * ByteBuffer#position()} of the given bb. Does NOT change the position or limit or mark of the given ByteBuffer. * Returns the number of the copied bytes. */ default int copyTo(@NotNull ByteBuffer bb) throws BufferUnderflowException { int pos = bb.position(); int len = (int) Math.min(bb.remaining(), readRemaining()); int i; for (i = 0; i < len - 7; i += 8) bb.putLong(pos + i, readLong(start() + i)); for (; i < len; i++) bb.put(pos + i, readByte(start() + i)); return len; }
@NotNull @Override public HeapBytesStore<Underlying> write(long writeOffset, @NotNull RandomDataInput bytes, long readOffset, long length) { long i; for (i = 0; i < length - 7; i += 8) { long x = bytes.readLong(readOffset + i); writeLong(writeOffset + i, x); } for (; i < length; i++) { byte x = bytes.readByte(readOffset + i); writeByte(writeOffset + i, x); } return this; }
@Override @NotNull public Bytes<Void> write(@NotNull RandomDataInput bytes, long offset, long length) throws BufferUnderflowException, BufferOverflowException { assert singleThreadedAccess(); if (bytes instanceof BytesStore) write((BytesStore) bytes, offset, length); else if (length == 8) writeLong(bytes.readLong(offset)); else if (length > 0) BytesInternal.writeFully(bytes, offset, length, this); return this; }
public void write0(long offsetInRDO, @NotNull RandomDataInput bytes, long offset, long length) throws BufferUnderflowException { long i = 0; for (; i < length - 7; i += 8) { writeLong(offsetInRDO + i, bytes.readLong(offset + i)); } for (; i < length; i++) { writeByte(offsetInRDO + i, bytes.readByte(offset + i)); } }
@NotNull @Override public Bytes<Underlying> write(@NotNull RandomDataInput bytes, long offset, long length) throws BufferUnderflowException, BufferOverflowException { if (length == 8) { writeLong(bytes.readLong(offset)); } else if (length >= 16 && bytes.isDirectMemory()) { rawCopy(bytes, offset, length); } else { BytesInternal.writeFully(bytes, offset, length, this); } return this; }
/** * Read a long which is zero padded (high bytes) if the available bytes is less than 8. * If the offset is at or beyond the readLimit, this will return 0L. * * @param offset to read from * @return the long which might be padded. */ default long readIncompleteLong(long offset) { long left = readLimit() - offset; long l; try { if (left >= 8) return readLong(offset); if (left == 4) return readInt(offset); l = 0; for (int i = 0, remaining = (int) left; i < remaining; i++) { l |= (long) readUnsignedByte(offset + i) << (i * 8); } } catch (BufferUnderflowException e) { throw new AssertionError(e); } return l; }
public static void writeFully(@org.jetbrains.annotations.NotNull @NotNull RandomDataInput bytes, long offset, long length, @org.jetbrains.annotations.NotNull StreamingDataOutput sdo) throws BufferUnderflowException, BufferOverflowException { long i = 0; for (; i < length - 7; i += 8) sdo.writeLong(bytes.readLong(offset + i)); if (i < length - 3) { sdo.writeInt(bytes.readInt(offset + i)); i += 4; } for (; i < length; i++) sdo.writeByte(bytes.readByte(offset + i)); }
public static boolean bytesEqual( @org.jetbrains.annotations.NotNull @NotNull RandomDataInput a, long offset, @org.jetbrains.annotations.NotNull @NotNull RandomDataInput second, long secondOffset, long len) throws BufferUnderflowException { long i = 0; while (len - i >= 8L) { if (a.readLong(offset + i) != second.readLong(secondOffset + i)) return false; i += 8L; } if (len - i >= 4L) { if (a.readInt(offset + i) != second.readInt(secondOffset + i)) return false; i += 4L; } if (len - i >= 2L) { if (a.readShort(offset + i) != second.readShort(secondOffset + i)) return false; i += 2L; } if (i < len) return a.readByte(offset + i) == second.readByte(secondOffset + i); return true; }
try { for (; end >= start + 16 && end >= readLimit + 16; end -= 8) { if (bytes.readLong(end - 8) != 0) break;