com.google.common.primitives.UnsignedBytes#toString ( )源码实例Demo

下面列出了com.google.common.primitives.UnsignedBytes#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mongowp   文件: ParsingTools.java
protected static BinarySubtype getBinarySubtype(byte readByte) {
  switch (readByte) {
    case 0x00:
      return BinarySubtype.GENERIC;
    case 0x01:
      return BinarySubtype.FUNCTION;
    case 0x02:
      return BinarySubtype.OLD_BINARY;
    case 0x03:
      return BinarySubtype.OLD_UUID;
    case 0x04:
      return BinarySubtype.UUID;
    case 0x05:
      return BinarySubtype.MD5;
    default: {
      if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
        return BinarySubtype.USER_DEFINED;
      } else {
        throw new AssertionError(
            "Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
      }
    }
  }
}
 
源代码2 项目: mongowp   文件: MongoBsonTranslator.java
protected static BinarySubtype getBinarySubtype(byte readByte) {
  switch (readByte) {
    case 0x00:
      return BinarySubtype.GENERIC;
    case 0x01:
      return BinarySubtype.FUNCTION;
    case 0x02:
      return BinarySubtype.OLD_BINARY;
    case 0x03:
      return BinarySubtype.OLD_UUID;
    case 0x04:
      return BinarySubtype.UUID;
    case 0x05:
      return BinarySubtype.MD5;
    default:
    {
      if (UnsignedBytes.compare(readByte, FIRST_USER_DEFINED) >= 0) {
        return BinarySubtype.USER_DEFINED;
      } else {
        throw new AssertionError(
                "Unrecognized binary type 0x" + UnsignedBytes.toString(readByte, 16));
      }
    }
  }
}
 
源代码3 项目: ipmi4j   文件: AsfRsspSessionAuthentication.java
@Nonnull
public static Payload fromWire(@Nonnull ByteBuffer buffer) {
    if (!buffer.hasRemaining())
        return EndOfList.INSTANCE;

    byte type = buffer.get();
    AbstractWireable.assertWireByte(buffer, (byte) 0, "reserved byte");
    short length = buffer.getShort();
    byte[] data = new byte[length - 4];
    buffer.get(data);

    switch (buffer.get()) {
        case 0:
            return EndOfList.INSTANCE;
        case 1:
            return Code.fromByte(AuthenticationAlgorithm.class, data[0]);
        case 2:
            return Code.fromByte(IntegrityAlgorithm.class, data[0]);
        default:
            throw new IllegalArgumentException("Unknown algorithm type 0x" + UnsignedBytes.toString(type, 16));
    }
}
 
源代码4 项目: exonum-java-binding   文件: BytesTest.java
@Test
void toHexStringAllHexNumbersLower() {
  for (byte b = 0; b <= 0xF; b++) {
    String expected = "0" + UnsignedBytes.toString(b, 16);
    assertThat(Bytes.toHexString(bytes(b)), equalTo(expected));
  }
}
 
源代码5 项目: exonum-java-binding   文件: BytesTest.java
@Test
void toHexStringAllHexNumbersUpper() {
  for (int i = 1; i <= 0xF; i++) {
    byte b = (byte) (i << 4);
    String expected = UnsignedBytes.toString(b, 16);
    assertThat(Bytes.toHexString(bytes(b)), equalTo(expected));
  }
}
 
源代码6 项目: mongowp   文件: DefaultNettyBsonLowLevelReader.java
@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");
}
 
源代码7 项目: ipmi4j   文件: AbstractIpmiCommand.java
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);
}
 
源代码8 项目: ipmi4j   文件: AbstractWireable.java
/** Reads a byte from the wire, and asserts it equal to the given expected value. */
public static void assertWireByte(@Nonnull ByteBuffer buffer, byte expectValue, @Nonnull String description) {
    byte actualValue = buffer.get();
    if (actualValue != expectValue)
        throw new IllegalArgumentException("In " + description + ": "
                + "Expected 0x" + UnsignedBytes.toString(expectValue, 16)
                + " but got 0x" + UnsignedBytes.toString(actualValue, 16));
}
 
源代码9 项目: ipmi4j   文件: AbstractWireable.java
@Nonnull
public static String toHexString(@CheckForNull byte... data) {
    if (data == null)
        return "<null>";
    StringBuilder buf = new StringBuilder();
    buf.append("(").append(data.length).append(" bytes) ");
    for (byte b : data) {
        String s = UnsignedBytes.toString(b, 16);
        if (s.length() < 2)
            buf.append('0');
        buf.append(s).append(' ');
    }
    buf.setLength(buf.length() - 1);
    return buf.toString();
}
 
源代码10 项目: ipmi4j   文件: Code.java
@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));
}
 
源代码11 项目: mongowp   文件: ParsingTools.java
/**
 * Translate a byte to the {@link BsonType} it represents, as specified on the
 * <a href="http://bsonspec.org/spec.html">BSON Spec</a>
 *
 * @param typeByte
 * @return
 * @throws NettyBsonReaderException
 */
@Nonnull
protected static BsonType getBsonType(byte typeByte) throws NettyBsonReaderException {
  switch (typeByte) {
    case 0x01:
      return DOUBLE;
    case 0x02:
      return STRING;
    case 0x03:
      return DOCUMENT;
    case 0x04:
      return ARRAY;
    case 0x05:
      return BINARY;
    case 0x06:
      return UNDEFINED;
    case 0x07:
      return OBJECT_ID;
    case 0x08:
      return BOOLEAN;
    case 0x09:
      return DATETIME;
    case 0x0A:
      return NULL;
    case 0x0B:
      return REGEX;
    case 0x0C:
      return DB_POINTER;
    case 0x0D:
      return JAVA_SCRIPT;
    case 0x0E:
      return DEPRECATED;
    case 0x0F:
      return JAVA_SCRIPT_WITH_SCOPE;
    case 0x10:
      return INT32;
    case 0x11:
      return TIMESTAMP;
    case 0x12:
      return INT64;
    case 0x13:
      return DECIMAL128;
    case UnsignedBytes.MAX_VALUE:
      return MIN;
    case 0x7F:
      return MAX;
    default:
      throw new NettyBsonReaderException("It is not defined the type associated with the byte "
          + UnsignedBytes.toString(typeByte, 16));
  }
}
 
源代码12 项目: ipmi4j   文件: SDRDeviceSubtype.java
@Override
public String toString() {
    return "Unknown(0x" + UnsignedBytes.toString(getCode(), 16) + ")";
}
 
源代码13 项目: ipmi4j   文件: Code.java
@Nonnull
public static <T extends Enum<T> & Code.DescriptiveWrapper> String toString(@Nonnull T value) {
    return value.name() + "(0x" + UnsignedBytes.toString(value.getCode(), 16) + "): " + value.getDescription();
}