com.google.common.primitives.Bytes类的使用及代码示例

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

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

Bytes介绍

[英]Static utility methods pertaining to byte primitives, that are not already found in either Byte or Arrays, and interpret bytes as neither signed nor unsigned. The methods which specifically treat bytes as signed or unsigned are found in SignedBytesand UnsignedBytes.

See the Guava User Guide article on primitive utilities.
[中]与字节原语相关的静态实用程序方法,在字节或数组中都找不到,并将字节解释为既没有符号也没有符号。在SignedBytes和UnsignedBytes中可以找到专门将字节视为有符号或无符号的方法。
请参阅关于primitive utilities的Guava用户指南文章。

代码示例

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

/**
   * Get auth plugin data.
   * 
   * @return auth plugin data
   */
  public byte[] getAuthPluginData() {
    return Bytes.concat(authPluginDataPart1, authPluginDataPart2);
  }
}

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

/**
 * Returns the index of the first appearance of the value {@code target} in {@code array}.
 *
 * @param array an array of {@code byte} values, possibly empty
 * @param target a primitive {@code byte} value
 * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
 *     such index exists.
 */
public static int indexOf(byte[] array, byte target) {
 return indexOf(array, target, 0, array.length);
}

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

public void testAsList_subList_toArray_roundTrip() {
 byte[] array = {(byte) 0, (byte) 1, (byte) 2, (byte) 3};
 List<Byte> list = Bytes.asList(array);
 assertTrue(Arrays.equals(new byte[] {(byte) 1, (byte) 2}, Bytes.toArray(list.subList(1, 3))));
 assertTrue(Arrays.equals(new byte[] {}, Bytes.toArray(list.subList(2, 2))));
}

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

private static List<Byte> asList(Byte[] values) {
 byte[] temp = new byte[values.length];
 for (int i = 0; i < values.length; i++) {
  temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize).
 }
 return Bytes.asList(temp);
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public PersistedData serializeCollection(Collection<Byte> value, SerializationContext context) {
  return context.create(Bytes.toArray(value));
}

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

/**
 * Returns the index of the last appearance of the value {@code target} in {@code array}.
 *
 * @param array an array of {@code byte} values, possibly empty
 * @param target a primitive {@code byte} value
 * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no
 *     such index exists.
 */
public static int lastIndexOf(byte[] array, byte target) {
 return lastIndexOf(array, target, 0, array.length);
}

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

@Override
public int hashCode() {
 int result = 1;
 for (int i = start; i < end; i++) {
  result = 31 * result + Bytes.hashCode(array[i]);
 }
 return result;
}

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

private static void assertEquals(byte[] expected, byte[] actual) {
  assertEquals(Bytes.asList(expected), Bytes.asList(actual));
 }
}

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

public void testToArray_withNull() {
 List<Byte> list = Arrays.asList((byte) 0, (byte) 1, null);
 try {
  Bytes.toArray(list);
  fail();
 } catch (NullPointerException expected) {
 }
}

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

/**
 * Returns the index of the last appearance of the value {@code target} in {@code array}.
 *
 * @param array an array of {@code byte} values, possibly empty
 * @param target a primitive {@code byte} value
 * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no
 *     such index exists.
 */
public static int lastIndexOf(byte[] array, byte target) {
 return lastIndexOf(array, target, 0, array.length);
}

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

@Override
public int hashCode() {
 int result = 1;
 for (int i = start; i < end; i++) {
  result = 31 * result + Bytes.hashCode(array[i]);
 }
 return result;
}

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

/**
   * Get auth plugin data.
   * 
   * @return auth plugin data
   */
  public byte[] getAuthPluginData() {
    return Bytes.concat(authPluginDataPart1, authPluginDataPart2);
  }
}

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

public void testToArray() {
 // need explicit type parameter to avoid javac warning!?
 List<Byte> none = Arrays.<Byte>asList();
 assertTrue(Arrays.equals(EMPTY, Bytes.toArray(none)));
 List<Byte> one = Arrays.asList((byte) 1);
 assertTrue(Arrays.equals(ARRAY1, Bytes.toArray(one)));
 byte[] array = {(byte) 0, (byte) 1, (byte) 0x55};
 List<Byte> three = Arrays.asList((byte) 0, (byte) 1, (byte) 0x55);
 assertTrue(Arrays.equals(array, Bytes.toArray(three)));
 assertTrue(Arrays.equals(array, Bytes.toArray(Bytes.asList(array))));
}

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

/**
 * Returns the index of the first appearance of the value {@code target} in {@code array}.
 *
 * @param array an array of {@code byte} values, possibly empty
 * @param target a primitive {@code byte} value
 * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
 *     such index exists.
 */
public static int indexOf(byte[] array, byte target) {
 return indexOf(array, target, 0, array.length);
}

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

public static IterableChecker<List<Byte>, Byte> check(byte[] actualByteArray) {
 return check(actualByteArray == null ? null : Bytes.asList(actualByteArray));
}

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

public void testToArray_withConversion() {
 byte[] array = {(byte) 0, (byte) 1, (byte) 2};
 List<Byte> bytes = Arrays.asList((byte) 0, (byte) 1, (byte) 2);
 List<Short> shorts = Arrays.asList((short) 0, (short) 1, (short) 2);
 List<Integer> ints = Arrays.asList(0, 1, 2);
 List<Float> floats = Arrays.asList((float) 0, (float) 1, (float) 2);
 List<Long> longs = Arrays.asList((long) 0, (long) 1, (long) 2);
 List<Double> doubles = Arrays.asList((double) 0, (double) 1, (double) 2);
 assertTrue(Arrays.equals(array, Bytes.toArray(bytes)));
 assertTrue(Arrays.equals(array, Bytes.toArray(shorts)));
 assertTrue(Arrays.equals(array, Bytes.toArray(ints)));
 assertTrue(Arrays.equals(array, Bytes.toArray(floats)));
 assertTrue(Arrays.equals(array, Bytes.toArray(longs)));
 assertTrue(Arrays.equals(array, Bytes.toArray(doubles)));
}

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

/**
 * Returns the index of the last appearance of the value {@code target} in {@code array}.
 *
 * @param array an array of {@code byte} values, possibly empty
 * @param target a primitive {@code byte} value
 * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no
 *     such index exists.
 */
public static int lastIndexOf(byte[] array, byte target) {
 return lastIndexOf(array, target, 0, array.length);
}

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

@Override
public int hashCode() {
 int result = 1;
 for (int i = start; i < end; i++) {
  result = 31 * result + Bytes.hashCode(array[i]);
 }
 return result;
}

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

@Override
public byte[] getCacheKey()
{
 byte[] cacheKey = new byte[]{ExtractionCacheHelper.CACHE_TYPE_ID_CASCADE};
 return Bytes.concat(cacheKey, chainedExtractionFn.getCacheKey());
}

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

public void testAsList_toArray_roundTrip() {
 byte[] array = {(byte) 0, (byte) 1, (byte) 2};
 List<Byte> list = Bytes.asList(array);
 byte[] newArray = Bytes.toArray(list);
 // Make sure it returned a copy
 list.set(0, (byte) 4);
 assertTrue(Arrays.equals(new byte[] {(byte) 0, (byte) 1, (byte) 2}, newArray));
 newArray[1] = (byte) 5;
 assertEquals((byte) 1, (byte) list.get(1));
}

相关文章