/** * Read a byte[] from memory. * * @return the length actually read. * @throws BufferUnderflowException if the offset is outside the limits of the Bytes */ default int copyTo(@NotNull byte[] bytes) throws BufferUnderflowException { int len = (int) Math.min(bytes.length, readRemaining()); for (int i = 0; i < len; i++) bytes[i] = readByte(start() + i); return len; }
/** * 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; }
private static void toString(@org.jetbrains.annotations.NotNull @NotNull RandomDataInput bytes, @org.jetbrains.annotations.NotNull @NotNull Appendable sb, long start, long readPosition, long writePosition, long end) throws BufferUnderflowException { try { // before if (start < bytes.start()) start = bytes.start(); long realCapacity = bytes.realCapacity(); if (end > realCapacity) end = realCapacity; if (readPosition >= start && bytes instanceof Bytes) { long last = Math.min(readPosition, end); toString(bytes, sb, start, last); sb.append('\u01C1'); } toString(bytes, sb, Math.max(readPosition, start), Math.min(writePosition, end)); if (writePosition <= end) { if (bytes instanceof Bytes) sb.append('\u2021'); toString(bytes, sb, writePosition, end); } } catch (Exception e) { try { sb.append(' ').append(e.toString()); } catch (IOException e1) { throw new AssertionError(e); } } }
.append(" ] "); try { long start = Math.max(bytes.start(), readPosition - 64); long end = Math.min(readLimit + 64, start + maxLength);
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(); }