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); }
public static IterableChecker<List<Byte>, Byte> check(byte[] actualByteArray) { return check(actualByteArray == null ? null : Bytes.asList(actualByteArray)); }
@Override public List<Byte> deserializeCollection(PersistedData data, DeserializationContext context) { if (data.isBytes()) { return Lists.newArrayList(Bytes.asList(data.getAsBytes())); } return Lists.newArrayList(); } }
public void testAsListEmpty() { assertSame(Collections.emptyList(), Bytes.asList(EMPTY)); }
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); } }
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); }
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); }
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)); }
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)))); }
@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; } };
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)); }
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)))); }
public IterableSubject asList() { return checkNoNeedToDisplayBothValues("asList()").that(Bytes.asList(actual())); } }
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]); } } } }
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(); }
break; case TINYINT_TYPE: value.setByteVal(new TByteColumn(Bytes.asList(Arrays.copyOfRange(byteVars, 0, size)), nullMasks)); break;
@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)); } }
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); }