com.google.common.primitives.Bytes.asList()方法的使用及代码示例

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

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

Bytes.asList介绍

[英]Returns a fixed-size list backed by the specified array, similar to Arrays#asList(Object[]). The list supports List#set(int,Object), but any attempt to set a value to null will result in a NullPointerException.

The returned list maintains the values, but not the identities, of Byte objects written to or read from it. For example, whether list.get(0) == list.get(0) is true for the returned list is unspecified.
[中]返回指定数组支持的固定大小列表,类似于数组#asList(Object[])。该列表支持list#set(int,Object),但任何将值设置为null的尝试都将导致NullPointerException。
返回的列表维护写入或读取的字节对象的值,但不维护其标识。例如,是否列出。获取(0)=列表。对于未指定的返回列表,get(0)为true。

代码示例

代码示例来源: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: google/guava

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

代码示例来源: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 testReadFully() throws IOException {
 DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data));
 byte[] b = new byte[data.length];
 in.readFully(b);
 assertEquals(Bytes.asList(data), Bytes.asList(b));
}

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

@Override
  public List<Byte> deserializeCollection(PersistedData data, DeserializationContext context) {
    if (data.isBytes()) {
      return Lists.newArrayList(Bytes.asList(data.getAsBytes()));
    }
    return Lists.newArrayList();
  }
}

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

public void testAsListEmpty() {
 assertSame(Collections.emptyList(), Bytes.asList(EMPTY));
}

代码示例来源:origin: prestodb/presto

private static BigInteger toBigInteger(int[] data)
  {
    byte[] array = new byte[data.length * 4];
    ByteBuffer byteBuffer = ByteBuffer.wrap(array);
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(data);

    Collections.reverse(Bytes.asList(array));
    array[0] &= ~(1 << 7);
    return new BigInteger((array[0] & (1 << 7)) > 0 ? -1 : 1, array);
  }
}

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

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

代码示例来源:origin: prestodb/presto

private static int[] toInt8Array(BigInteger value)
{
  byte[] bigIntegerBytes = value.toByteArray();
  Collections.reverse(Bytes.asList(bigIntegerBytes));
  byte[] bytes = new byte[8 * 4 + 1];
  System.arraycopy(bigIntegerBytes, 0, bytes, 0, bigIntegerBytes.length);
  return toInt8Array(bytes);
}

代码示例来源: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));
}

代码示例来源: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/truth

@Override
 public Object apply(@NullableDecl Object input) {
  if (input != null && input.getClass().isArray()) {
   Iterable<?> iterable;
   if (input.getClass() == boolean[].class) {
    iterable = Booleans.asList((boolean[]) input);
   } else if (input.getClass() == int[].class) {
    iterable = Ints.asList((int[]) input);
   } else if (input.getClass() == long[].class) {
    iterable = Longs.asList((long[]) input);
   } else if (input.getClass() == short[].class) {
    iterable = Shorts.asList((short[]) input);
   } else if (input.getClass() == byte[].class) {
    iterable = Bytes.asList((byte[]) input);
   } else if (input.getClass() == double[].class) {
    iterable = doubleArrayAsString((double[]) input);
   } else if (input.getClass() == float[].class) {
    iterable = floatArrayAsString((float[]) input);
   } else if (input.getClass() == char[].class) {
    iterable = Chars.asList((char[]) input);
   } else {
    iterable = Arrays.asList((Object[]) input);
   }
   return Iterables.transform(iterable, STRINGIFY);
  }
  return input;
 }
};

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

public void testReadBytes() throws IOException {
 ByteProcessor<byte[]> processor =
   new ByteProcessor<byte[]>() {
    private final ByteArrayOutputStream out = new ByteArrayOutputStream();
    @Override
    public boolean processBytes(byte[] buffer, int offset, int length) throws IOException {
     if (length >= 0) {
      out.write(buffer, offset, length);
     }
     return true;
    }
    @Override
    public byte[] getResult() {
     return out.toByteArray();
    }
   };
 File asciiFile = getTestFile("ascii.txt");
 byte[] result = Files.readBytes(asciiFile, processor);
 assertEquals(Bytes.asList(Files.toByteArray(asciiFile)), Bytes.asList(result));
}

代码示例来源: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/truth

public IterableSubject asList() {
  return checkNoNeedToDisplayBothValues("asList()").that(Bytes.asList(actual()));
 }
}

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

public void testToArray_threadSafe() {
 for (int delta : new int[] {+1, 0, -1}) {
  for (int i = 0; i < VALUES.length; i++) {
   List<Byte> list = Bytes.asList(VALUES).subList(0, i);
   Collection<Byte> misleadingSize = Helpers.misleadingSizeCollection(delta);
   misleadingSize.addAll(list);
   byte[] arr = Bytes.toArray(misleadingSize);
   assertEquals(i, arr.length);
   for (int j = 0; j < i; j++) {
    assertEquals(VALUES[j], arr[j]);
   }
  }
 }
}

代码示例来源:origin: SpongePowered/SpongeAPI

private static List<?> primitiveArrayToList(Object obj) {
  if (obj instanceof boolean[]) {
    return Booleans.asList((boolean[])obj);
  } else if (obj instanceof char[]) {
    return Chars.asList((char[])obj);
  } else if (obj instanceof byte[]) {
    return Bytes.asList((byte[])obj);
  } else if (obj instanceof short[]) {
    return Shorts.asList((short[])obj);
  } else if (obj instanceof int[]) {
    return Ints.asList((int[])obj);
  } else if (obj instanceof long[]) {
    return Longs.asList((long[])obj);
  } else if (obj instanceof float[]) {
    return Floats.asList((float[])obj);
  } else if (obj instanceof double[]) {
    return Doubles.asList((double[])obj);
  }
  return Collections.<Object>emptyList();
}

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

break;
case TINYINT_TYPE:
 value.setByteVal(new TByteColumn(Bytes.asList(Arrays.copyOfRange(byteVars, 0, size)),
   nullMasks));
 break;

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

@Test
 public void testToBytes()
 {
  BitmapFactory bf = new RoaringBitmapFactory();
  ImmutableRTreeObjectStrategy rTreeObjectStrategy = new ImmutableRTreeObjectStrategy(bf);
  RTree rTree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
  rTree.insert(new float[]{0, 0}, 1);
  ImmutableRTree immutableRTree = ImmutableRTree.newImmutableFromMutable(rTree);
  byte[] bytes1 = immutableRTree.toBytes();

  GenericIndexed<ImmutableRTree> genericIndexed = GenericIndexed.fromIterable(
    Arrays.asList(immutableRTree, immutableRTree),
    rTreeObjectStrategy
  );

  ImmutableRTree deserializedTree = genericIndexed.get(0);
  byte[] bytes2 = deserializedTree.toBytes();
  org.junit.Assert.assertEquals(Bytes.asList(bytes1), Bytes.asList(bytes2));
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testByteList() {
 ByteList bl = new ByteList();
 bl.checksum = asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0"));
 assertEquals(json.toJson(bl), "{\"checksum\":\"1dda05ed139664f1f89b9dec482b77c0\"}");
 assertEquals(json.fromJson(json.toJson(bl), ByteList.class).checksum, bl.checksum);
}

相关文章