/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string containing the supplied {@code byte} values separated by {@code separator}. * For example, {@code join(":", (byte) 1, (byte) 2, (byte) 255)} returns the string {@code * "1:2:255"}. * * @param separator the text that should appear between consecutive values in the resulting string * (but not at the start or end) * @param array an array of {@code byte} values, possibly empty */ public static String join(String separator, byte... array) { checkNotNull(separator); if (array.length == 0) { return ""; } // For pre-sizing a builder, just get the right order of magnitude StringBuilder builder = new StringBuilder(array.length * (3 + separator.length())); builder.append(toInt(array[0])); for (int i = 1; i < array.length; i++) { builder.append(separator).append(toString(array[i])); } return builder.toString(); }
/** * Returns a string containing the supplied {@code byte} values separated by {@code separator}. * For example, {@code join(":", (byte) 1, (byte) 2, (byte) 255)} returns the string {@code * "1:2:255"}. * * @param separator the text that should appear between consecutive values in the resulting string * (but not at the start or end) * @param array an array of {@code byte} values, possibly empty */ public static String join(String separator, byte... array) { checkNotNull(separator); if (array.length == 0) { return ""; } // For pre-sizing a builder, just get the right order of magnitude StringBuilder builder = new StringBuilder(array.length * (3 + separator.length())); builder.append(toInt(array[0])); for (int i = 1; i < array.length; i++) { builder.append(separator).append(toString(array[i])); } return builder.toString(); }
public void testToString() { // We can easily afford to test this exhaustively. for (int i = 0; i <= 0xff; i++) { assertEquals(Integer.toString(i), UnsignedBytes.toString((byte) i)); } }
public void testToStringWithRadix() { // We can easily afford to test this exhaustively. for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { for (int i = 0; i <= 0xff; i++) { assertEquals(Integer.toString(i, radix), UnsignedBytes.toString((byte) i, radix)); } } }
/** * Returns a string containing the supplied {@code byte} values separated by {@code separator}. * For example, {@code join(":", (byte) 1, (byte) 2, (byte) 255)} returns the string {@code * "1:2:255"}. * * @param separator the text that should appear between consecutive values in the resulting string * (but not at the start or end) * @param array an array of {@code byte} values, possibly empty */ public static String join(String separator, byte... array) { checkNotNull(separator); if (array.length == 0) { return ""; } // For pre-sizing a builder, just get the right order of magnitude StringBuilder builder = new StringBuilder(array.length * (3 + separator.length())); builder.append(toInt(array[0])); for (int i = 1; i < array.length; i++) { builder.append(separator).append(toString(array[i])); } return builder.toString(); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta public static String toString(byte x) { return toString(x, 10); }
/** * Returns a string representation of x, where x is treated as unsigned. * * @since 13.0 */ @Beta @CheckReturnValue public static String toString(byte x) { return toString(x, 10); }
public void fromWireChecksum(@Nonnull ByteBuffer buffer, @Nonnegative int start, @Nonnull String description) { byte expect = toChecksum(buffer, start); byte actual = buffer.get(); if (expect != actual) throw new IllegalArgumentException("Checksum failure: " + description + ": expected=" + UnsignedBytes.toString(expect, 16) + " actual=" + UnsignedBytes.toString(actual, 16) + "; command=" + getClass().getSimpleName() + "; data=" + this); }
@Nonnull public static <T extends Enum<T> & Code.Wrapper> T fromByte(@Nonnull Class<T> type, byte code) { for (T value : type.getEnumConstants()) if (value.getCode() == code) return value; throw new IllegalArgumentException("Unknown " + type.getSimpleName() + " code 0x" + UnsignedBytes.toString(code, 16)); }
@Override public String toString() { return "Unknown(0x" + UnsignedBytes.toString(getCode(), 16) + ")"; } }
@Override public void toStringBuilder(StringBuilder buf, int depth) { super.toStringBuilder(buf, depth); appendValue(buf, depth, "FruDeviceId", "0x" + UnsignedBytes.toString(fruDeviceId, 16)); } }
@Override public void toStringBuilder(StringBuilder buf, int depth) { appendHeader(buf, depth, getClass().getSimpleName()); depth++; appendValue(buf, depth, "MessageTag", "0x" + UnsignedBytes.toString(messageTag, 16)); appendValue(buf, depth, "StatusCode", statusCode); appendValue(buf, depth, "SystemSessionId", "0x" + Integer.toHexString(systemSessionId)); appendValue(buf, depth, "KeyExchangeAuthenticationCode", toHexString(keyExchangeAuthenticationCode)); } }
@Override public void toStringBuilder(StringBuilder buf, int depth) { appendHeader(buf, depth, getClass().getSimpleName()); depth++; appendValue(buf, depth, "MessageTag", "0x" + UnsignedBytes.toString(messageTag, 16)); appendValue(buf, depth, "StatusCode", statusCode); appendValue(buf, depth, "ConsoleSessionId", "0x" + Integer.toHexString(consoleSessionId)); appendValue(buf, depth, "IntegrityCheckValue", toHexString(integrityCheckValue)); } }
@Override BsonBoolean readBoolean(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException { byte readByte = byteBuf.readByte(); if (readByte == 0x00) { return FalseBsonBoolean.getInstance(); } if (readByte == 0x01) { return TrueBsonBoolean.getInstance(); } throw new NettyBsonReaderException("Unexpected boolean byte. 0x00 or " + "0x01 was expected, but 0x" + UnsignedBytes.toString(readByte, 16) + " was read"); }