java.lang.Byte类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中java.lang.Byte类的一些代码示例,展示了Byte类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Byte类的具体详情如下:
包路径:java.lang.Byte
类名称:Byte

Byte介绍

[英]The wrapper for the primitive type byte.
[中]基元类型字节的包装器。

代码示例

代码示例来源:origin: apache/incubator-dubbo

public static Byte boxed(byte v) {
  return Byte.valueOf(v);
}

代码示例来源:origin: ctripcorp/apollo

@Override
 public Byte apply(String input) {
  return Byte.parseByte(input);
 }
};

代码示例来源:origin: apache/incubator-dubbo

public static byte unboxed(Byte v) {
  return v == null ? 0 : v.byteValue();
}

代码示例来源:origin: spring-projects/spring-loaded

public String setByte() throws Exception {
  Field f = JLRFSetTheRestVariant.class.getDeclaredField("b");
  f.set(this, new Byte("123"));
  return Byte.toString(b);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Get a byte associated with the given configuration key.
 *
 * @param key The configuration key.
 * @param defaultValue The default value.
 * @return The associated byte.
 * @throws ClassCastException is thrown if the key maps to an
 * object that is not a Byte.
 * @throws NumberFormatException is thrown if the value mapped
 * by the key has not a valid number format.
 */
public byte getByte(String key, byte defaultValue) {
  return getByte(key, new Byte(defaultValue)).byteValue();
}

代码示例来源:origin: log4j/log4j

/**
 * Returns a Byte instance representing the specified byte.
 * Byte.valueOf was added in JDK 1.5.
 *
 * @param b a byte value.
 * @return a Byte instance representing b.
 */
protected static Byte valueOf(final byte b) {
  return new Byte(b);
}

代码示例来源:origin: apache/flink

/**
 * Returns the Byte value for the given key. If the key does not exists it will return the default value given.
 * The method fails if the value is not a Byte.
 */
public byte getByte(String key, byte defaultValue) {
  addToDefaults(key, Byte.toString(defaultValue));
  String value = get(key);
  if (value == null) {
    return defaultValue;
  } else {
    return Byte.valueOf(value);
  }
}

代码示例来源:origin: voldemort/voldemort

public StringOrder toObject(byte[] bytes) {
    return new StringOrder(Byte.valueOf(bytes[0]).intValue());
  }
}

代码示例来源:origin: netty/netty

/**
 * Helper method called by {@link #toString()} in order to convert a single map key into a string.
 * This is protected to allow subclasses to override the appearance of a given key.
 */
protected String keyToString(byte key) {
  return Byte.toString(key);
}

代码示例来源:origin: google/guava

public void testCompare() {
 for (byte x : VALUES) {
  for (byte y : VALUES) {
   // Only compare the sign of the result of compareTo().
   int expected = Byte.valueOf(x).compareTo(y);
   int actual = SignedBytes.compare(x, y);
   if (expected == 0) {
    assertEquals(x + ", " + y, expected, actual);
   } else if (expected < 0) {
    assertTrue(
      x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual < 0);
   } else {
    assertTrue(
      x + ", " + y + " (expected: " + expected + ", actual" + actual + ")", actual > 0);
   }
  }
 }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testHashCode() {
  final MutableByte mutNumA = new MutableByte((byte) 0);
  final MutableByte mutNumB = new MutableByte((byte) 0);
  final MutableByte mutNumC = new MutableByte((byte) 1);
  assertTrue(mutNumA.hashCode() == mutNumA.hashCode());
  assertTrue(mutNumA.hashCode() == mutNumB.hashCode());
  assertFalse(mutNumA.hashCode() == mutNumC.hashCode());
  assertTrue(mutNumA.hashCode() == Byte.valueOf((byte) 0).hashCode());
}

代码示例来源:origin: traccar/traccar

public void set(String key, Byte value) {
  if (value != null) {
    attributes.put(key, value.intValue());
  }
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * Gets the value as a Byte instance.
 * 
 * @return the value as a Byte, never null
 */
public Object getValue() {
  return new Byte(this.value);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void parseNumberAsHex() {
  String aByte = "0x" + Integer.toHexString(Byte.valueOf(Byte.MAX_VALUE).intValue());
  String aShort = "0x" + Integer.toHexString(Short.valueOf(Short.MAX_VALUE).intValue());
  String anInteger = "0x" + Integer.toHexString(Integer.MAX_VALUE);
  String aLong = "0x" + Long.toHexString(Long.MAX_VALUE);
  String aReallyBigInt = "FEBD4E677898DFEBFFEE44";
  assertByteEquals(aByte);
  assertShortEquals(aShort);
  assertIntegerEquals(anInteger);
  assertLongEquals(aLong);
  assertEquals("BigInteger did not parse",
      new BigInteger(aReallyBigInt, 16), NumberUtils.parseNumber("0x" + aReallyBigInt, BigInteger.class));
}

代码示例来源:origin: skylot/jadx

public static String formatByte(byte b) {
  if (b == Byte.MAX_VALUE) {
    return "Byte.MAX_VALUE";
  }
  if (b == Byte.MIN_VALUE) {
    return "Byte.MIN_VALUE";
  }
  return "(byte) " + Byte.toString(b);
}

代码示例来源:origin: square/moshi

@Override public void toJson(JsonWriter writer, Byte value) throws IOException {
 writer.value(value.intValue() & 0xff);
}

代码示例来源:origin: apache/incubator-dubbo

public static Byte boxed(byte v) {
  return Byte.valueOf(v);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Constructs a new MutableByte parsing the given string.
 *
 * @param value  the string to parse, not null
 * @throws NumberFormatException if the string cannot be parsed into a byte
 * @since 2.5
 */
public MutableByte(final String value) {
  super();
  this.value = Byte.parseByte(value);
}

代码示例来源:origin: apache/incubator-dubbo

public static byte unboxed(Byte v) {
  return v == null ? 0 : v.byteValue();
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Converts an array of primitive bytes to objects.</p>
 *
 * <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
 *
 * @param array  a <code>byte</code> array
 * @return a <code>Byte</code> array, <code>null</code> if null array input
 */
public static Byte[] toObject(byte[] array) {
  if (array == null) {
    return null;
  } else if (array.length == 0) {
    return EMPTY_BYTE_OBJECT_ARRAY;
  }
  final Byte[] result = new Byte[array.length];
  for (int i = 0; i < array.length; i++) {
    result[i] = new Byte(array[i]);
  }
  return result;
}

相关文章