default void writeBigInteger(@org.jetbrains.annotations.NotNull @NotNull BigInteger bi) { byte[] bytes = bi.toByteArray(); writeStopBit(bytes.length); write(bytes); }
@Override public void write(byte[] b, int off, int len) throws IOException { try { sdo.write(b, off, len); } catch (@NotNull BufferOverflowException | IllegalArgumentException e) { throw new IOException(e); } }
private static void appendInt0(@org.jetbrains.annotations.NotNull @NotNull StreamingDataOutput out, int num) throws IllegalArgumentException, BufferOverflowException { if (num < 10) { out.writeByte((byte) ('0' + num)); } else if (num < 100) { out.writeShort((short) (num / 10 + (num % 10 << 8) + '0' * 0x101)); } else { byte[] numberBuffer = NUMBER_BUFFER.get(); // Extract digits into the end of the numberBuffer int endIndex = appendInt1(numberBuffer, num); // Bulk copy the digits into the front of the buffer out.write(numberBuffer, endIndex, numberBuffer.length - endIndex); } }
@org.jetbrains.annotations.NotNull @NotNull default S write8bit(@Nullable BytesStore bs) throws BufferOverflowException { if (bs == null) { writeStopBit(-1); } else { long offset = bs.readPosition(); long readRemaining = Math.min(writeRemaining(), bs.readLimit() - offset); writeStopBit(readRemaining); write(bs, offset, readRemaining); } return (S) this; }
@org.jetbrains.annotations.NotNull @NotNull default S writeSome(@org.jetbrains.annotations.NotNull @NotNull Bytes bytes) { try { long length = Math.min(bytes.readRemaining(), writeRemaining()); if (length + writePosition() >= 1 << 20) length = Math.min(bytes.readRemaining(), realCapacity() - writePosition()); write(bytes, bytes.readPosition(), length); if (length == bytes.readRemaining()) { bytes.clear(); } else { bytes.readSkip(length); if (bytes.writePosition() > bytes.realCapacity() / 2) bytes.compact(); } return (S) this; } catch (BufferOverflowException | BufferUnderflowException | IllegalArgumentException e) { throw new AssertionError(e); } }
default S write(@org.jetbrains.annotations.NotNull @NotNull BytesStore bytes) { assert bytes != this : "you should not write to yourself !"; try { return write(bytes, bytes.readPosition(), Math.min(writeRemaining(), bytes.readRemaining())); } catch (BufferOverflowException | BufferUnderflowException e) { throw new AssertionError(e); } }
default void writeWithLength(RandomDataInput bytes) { writeStopBit(bytes.readRemaining()); write(bytes); } }
private static void appendLong0(@org.jetbrains.annotations.NotNull @NotNull StreamingDataOutput out, long num) throws IllegalArgumentException, BufferOverflowException { if (num < 10) { out.writeByte((byte) ('0' + num)); } else if (num < 100) { out.writeShort((short) (num / 10 + (num % 10 << 8) + '0' * 0x101)); } else { byte[] numberBuffer = NUMBER_BUFFER.get(); // Extract digits into the end of the numberBuffer int endIndex = appendLong1(numberBuffer, num); // Bulk copy the digits into the front of the buffer out.write(numberBuffer, endIndex, numberBuffer.length - endIndex); } }
/** * Write all data or fail. */ @org.jetbrains.annotations.NotNull @NotNull default S write(@org.jetbrains.annotations.NotNull @NotNull RandomDataInput bytes) { assert bytes != this : "you should not write to yourself !"; try { return write(bytes, bytes.readPosition(), Math.min(writeRemaining(), bytes.readRemaining())); } catch (BufferOverflowException | BufferUnderflowException e) { throw new AssertionError(e); } }
public static void copy(@org.jetbrains.annotations.NotNull InputStream input, @org.jetbrains.annotations.NotNull StreamingDataOutput output) throws IOException, BufferOverflowException, IllegalArgumentException { @org.jetbrains.annotations.NotNull byte[] bytes = new byte[512]; for (int len; (len = input.read(bytes)) > 0; ) { output.write(bytes, 0, len); } }
@org.jetbrains.annotations.NotNull @NotNull default S write(@org.jetbrains.annotations.NotNull @NotNull byte[] bytes) throws BufferOverflowException { write(bytes, 0, bytes.length); return (S) this; }