/** * Append a portion of a String to the Bytes in ISO-8859-1 * * @param cs to copy * @param start index of the first char inclusive * @param end index of the last char exclusive. * @return this * @throws BufferOverflowException If the string as too large to write in the capacity available * @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded * @throws IndexOutOfBoundsException if the start or the end are not valid for the CharSequence */ default B append8bit(@NotNull CharSequence cs, int start, int end) throws IllegalArgumentException, BufferOverflowException, BufferUnderflowException, IndexOutOfBoundsException { if (cs instanceof BytesStore) { return write((BytesStore) cs, (long) start, end); } for (int i = start; i < end; i++) { char c = cs.charAt(i); if (c > 255) c = '?'; writeByte((byte) c); } return (B) this; }
public static void appendDateMillis(@org.jetbrains.annotations.NotNull @NotNull ByteStringAppender b, long timeInMS) throws BufferOverflowException { DateCache dateCache = dateCacheTL.get(); if (dateCache == null) { dateCacheTL.set(dateCache = new DateCache()); } long date = timeInMS / 86400000; if (dateCache.lastDay != date) { dateCache.lastDateStr = dateCache.dateFormat.format(new Date(timeInMS)).getBytes(ISO_8859_1); dateCache.lastDay = date; } else { assert dateCache.lastDateStr != null; } b.write(dateCache.lastDateStr); }
public static void appendBase10(@org.jetbrains.annotations.NotNull @NotNull ByteStringAppender out, long num) throws IllegalArgumentException, BufferOverflowException { if (num < 0) { if (num == Long.MIN_VALUE) { out.write(MIN_VALUE_TEXT); return; } out.writeByte((byte) '-'); num = -num; } appendLong0(out, num); }
public static void append(@org.jetbrains.annotations.NotNull @NotNull ByteStringAppender out, long num, int base) throws IllegalArgumentException, BufferOverflowException { if (num < 0) { if (num == Long.MIN_VALUE) { if (base == 10) out.write(MIN_VALUE_TEXT); else out.write(Long.toString(Long.MIN_VALUE, base)); return; } out.writeByte((byte) '-'); num = -num; } if (num == 0) { out.writeByte((byte) '0'); } else { switch (base) { case 10: appendLong0(out, num); break; case 16: appendBase16(out, num, 1); break; default: out.write(Long.toString(num, base)); break; } } }