@NotNull @Override @SuppressWarnings("rawtypes") public BytesRef read(Bytes in, long size, @Nullable BytesRef using) { if (size < 0L || size > (long) Integer.MAX_VALUE) { throw new IORuntimeException("byte[] size should be non-negative int, " + size + " given. Memory corruption?"); } int arrayLength = (int) size; if (using == null) { using = new BytesRef(new byte[arrayLength]); } else if (using.bytes.length < arrayLength) { using.bytes = new byte[arrayLength]; } in.read(using.bytes, 0, arrayLength); using.offset = 0; using.length = arrayLength; return using; }
private static String readString(Bytes in) { byte[] bytes = new byte[in.readShort()]; in.read(bytes); return new String(bytes); }
@NotNull default BigInteger readBigInteger() { int length = Maths.toUInt31(readStopBit()); if (length == 0) if (lenient()) return BigInteger.ZERO; else throw new BufferUnderflowException(); @NotNull byte[] bytes = new byte[length]; read(bytes); return new BigInteger(bytes); }
public int fetchOneMessage(@NotNull ExcerptTailer tailer, @NotNull byte[] using) { try (DocumentContext dc = tailer.readingDocument()) { return !dc.isPresent() ? -1 : dc.wire().bytes().read(using); } }
private static String readString(Bytes in) { byte[] bytes = new byte[in.readShort()]; in.read(bytes); return new String(bytes); }
@NotNull @Override public ByteBuffer read(@NotNull Bytes in, long size, @Nullable ByteBuffer using) { if (size < 0L || size > (long) Integer.MAX_VALUE) throw new IllegalArgumentException("ByteBuffer size should be non-negative int, " + size + " given. Memory corruption?"); int bufferCap = (int) size; if (using == null || using.capacity() < bufferCap) { using = ByteBuffer.allocate(bufferCap); } else { using.position(0); using.limit(bufferCap); } in.read(using); using.flip(); return using; }
@NotNull @Override public byte[] read(@NotNull Bytes in, long size, @Nullable byte[] using) { if (size < 0L || size > (long) Integer.MAX_VALUE) { throw new IORuntimeException("byte[] size should be non-negative int, " + size + " given. Memory corruption?"); } int arrayLength = (int) size; if (using == null || arrayLength != using.length) using = new byte[arrayLength]; in.read(using); return using; }