@org.jetbrains.annotations.NotNull @NotNull default S write8bit(@Nullable String s) throws BufferOverflowException { if (s == null) writeStopBit(-1); else write8bit(s, 0, (int) Math.min(writeRemaining(), s.length())); return (S) this; }
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); } }
/** * 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); } }
@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); } }