default long read(long offsetInRDI, byte[] bytes, int offset, int length) { try { int len = (int) Math.min(length, readLimit() - offsetInRDI); for (int i = 0; i < len; i++) bytes[offset + i] = readByte(offsetInRDI + i); return len; } catch (BufferUnderflowException e) { throw new AssertionError(e); } }
private static void toString(@org.jetbrains.annotations.NotNull @NotNull RandomDataInput bytes, @org.jetbrains.annotations.NotNull @NotNull StringBuilder sb) throws IllegalStateException { bytes.reserve(); assert bytes.start() <= bytes.readPosition(); assert bytes.readPosition() <= bytes.readLimit(); assert bytes.readLimit() <= bytes.realCapacity(); try { for (long i = bytes.readPosition(); i < bytes.readLimit(); i++) { sb.append((char) bytes.readUnsignedByte(i)); } } catch (BufferUnderflowException e) { sb.append(' ').append(e); } bytes.release(); }
/** * 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; }