@Test public void testCheckIndexWithWriteBytes3() { doTestCheckIndex( (appender, n) -> appender.writeBytes(b -> b.writeUtf8("Hello") .writeStopBit(12345) .writeStopBit(1.2) // float also supported. .writeInt(1))); }
public static void writeHistogram(@org.jetbrains.annotations.NotNull StreamingDataOutput out, @org.jetbrains.annotations.NotNull Histogram histogram) throws BufferOverflowException { out.writeStopBit(histogram.powersOf2()); out.writeStopBit(histogram.fractionBits()); out.writeStopBit(histogram.overRange()); out.writeStopBit(histogram.totalCount()); out.writeStopBit(histogram.floor()); int[] ints = histogram.sampleCount(); out.writeStopBit(ints.length); for (int i : ints) out.writeStopBit(i); }
default void writeBigInteger(@org.jetbrains.annotations.NotNull @NotNull BigInteger bi) { byte[] bytes = bi.toByteArray(); writeStopBit(bytes.length); write(bytes); }
default void writeBigDecimal(@org.jetbrains.annotations.NotNull @NotNull BigDecimal bd) { writeBigInteger(bd.unscaledValue()); writeStopBit(bd.scale()); }
@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; }
@org.jetbrains.annotations.NotNull @NotNull default S write8bit(@org.jetbrains.annotations.NotNull @NotNull CharSequence s, int start, int length) throws BufferOverflowException, IllegalArgumentException, IndexOutOfBoundsException { writeStopBit(length); for (int i = 0; i < length; i++) { char c = s.charAt(i + start); writeUnsignedByte(c); } return (S) this; }
default void writeWithLength(RandomDataInput bytes) { writeStopBit(bytes.readRemaining()); write(bytes); } }
@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 write8bit(@Nullable CharSequence cs) throws BufferOverflowException { if (cs == null) return writeStopBit(-1); if (cs instanceof BytesStore) return write8bit((BytesStore) cs); if (cs instanceof String) return write8bit((String) cs); return write8bit(cs, 0, cs.length()); }
@ForceInline public static void writeUtf8(@org.jetbrains.annotations.NotNull @NotNull StreamingDataOutput bytes, @Nullable CharSequence str) throws BufferOverflowException { if (str instanceof String) { writeUtf8(bytes, (String) str); return; } if (str == null) { bytes.writeStopBit(-1); } else { try { long utfLength = AppendableUtil.findUtf8Length(str); bytes.writeStopBit(utfLength); appendUtf8(bytes, str, 0, str.length()); } catch (IndexOutOfBoundsException e) { throw new AssertionError(e); } } }
public static void writeUtf8(@org.jetbrains.annotations.NotNull @NotNull StreamingDataOutput bytes, @org.jetbrains.annotations.Nullable @Nullable String str) throws BufferOverflowException { if (str == null) { bytes.writeStopBit(-1); return; } try { if (Jvm.isJava9Plus()) { byte[] strBytes = extractBytes(str); byte coder = StringUtils.getStringCoder(str); long utfLength = AppendableUtil.findUtf8Length(strBytes, coder); bytes.writeStopBit(utfLength); bytes.appendUtf8(strBytes, 0, str.length(), coder); } else { char[] chars = extractChars(str); long utfLength = AppendableUtil.findUtf8Length(chars); bytes.writeStopBit(utfLength); bytes.appendUtf8(chars, 0, chars.length); } } catch (IllegalArgumentException e) { throw new AssertionError(e); } }