public static void appendTimeMillis(@org.jetbrains.annotations.NotNull @NotNull ByteStringAppender b, long timeInMS) throws BufferOverflowException { int hours = (int) (timeInMS / (60 * 60 * 1000)); if (hours > 99) { b.append(hours); // can have over 24 hours. } else { b.writeByte((byte) (hours / 10 + '0')); b.writeByte((byte) (hours % 10 + '0')); } b.writeByte((byte) ':'); int minutes = (int) ((timeInMS / (60 * 1000)) % 60); b.writeByte((byte) (minutes / 10 + '0')); b.writeByte((byte) (minutes % 10 + '0')); b.writeByte((byte) ':'); int seconds = (int) ((timeInMS / 1000) % 60); b.writeByte((byte) (seconds / 10 + '0')); b.writeByte((byte) (seconds % 10 + '0')); b.writeByte((byte) '.'); int millis = (int) (timeInMS % 1000); b.writeByte((byte) (millis / 100 + '0')); b.writeByte((byte) (millis / 10 % 10 + '0')); b.writeByte((byte) (millis % 10 + '0')); }
public static void appendBase16(@org.jetbrains.annotations.NotNull @NotNull ByteStringAppender out, long num, int minDigits) throws IllegalArgumentException, BufferOverflowException { byte[] numberBuffer = NUMBER_BUFFER.get(); int len = 0; do { int digit = (int) (num & 0xF); num >>>= 4; numberBuffer[len++] = (byte) HEXADECIMAL[digit]; } while (--minDigits > 0 | num > 0); for (int i = len - 1; i >= 0; i--) out.writeByte(numberBuffer[i]); }
/** * 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 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 appendBase10(@org.jetbrains.annotations.NotNull @NotNull ByteStringAppender out, int num) throws IllegalArgumentException, BufferOverflowException { if (num < 0) { out.writeByte((byte) '-'); if (num == Integer.MIN_VALUE) { appendLong0(out, -(long) num); return; } num = -num; } appendInt0(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; } } }
endIndex = MIN_VALUE_TEXT.length; } else { out.writeByte((byte) '-'); num = -num; endIndex = appendLong1(numberBuffer, num);