@Override public PersistedData serializeCollection(Collection<Byte> value, SerializationContext context) { return context.create(Bytes.toArray(value)); }
public void testToArray_withNull() { List<Byte> list = Arrays.asList((byte) 0, (byte) 1, null); try { Bytes.toArray(list); fail(); } catch (NullPointerException expected) { } }
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 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))); }
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)))); }
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 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]); } } } }
type = Type.TINYINT_TYPE; nulls = toBitset(colValues.getByteVal().getNulls()); byteVars = Bytes.toArray(colValues.getByteVal().getValues()); size = byteVars.length; } else if (colValues.isSetI16Val()) {
@Test(groups = "short") @CassandraVersion("2.0.0") public void should_truncate_blob_parameter_when_max_length_exceeded_simple_statements() throws Exception { // given normal.setLevel(TRACE); queryLogger = QueryLogger.builder().withMaxParameterValueLength(6).build(); cluster().register(queryLogger); // when String query = "UPDATE test SET c_blob = ? WHERE pk = ?"; SimpleStatement ss = new SimpleStatement(query, ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1, 2, 3))), 42); session().execute(ss); // then String line = normalAppender.waitAndGet(10000); assertThat(line) .contains("Query completed normally") .contains(ipOfNode(1)) .contains("0x0102" + TRUNCATED_OUTPUT) .doesNotContain("0x010203"); }
/** * @return unencoded user data. */ public byte[] getUserData() { return userData == null ? null : Bytes.toArray(userData); }
/** * @return unencoded user data. */ public byte[] getUserData() { return userData == null ? null : Bytes.toArray(userData); }
/** * @return unencoded user data. */ public byte[] getUserData() { return userData == null ? null : Bytes.toArray(userData); }
@Test(groups = "short") public void should_truncate_blob_parameter_when_max_length_exceeded_bound_statements() throws Exception { // given normal.setLevel(TRACE); queryLogger = QueryLogger.builder().withMaxParameterValueLength(6).build(); cluster().register(queryLogger); // when String query = "UPDATE test SET c_blob = ? WHERE pk = ?"; PreparedStatement ps = session().prepare(query); BoundStatement bs = ps.bind(); bs.setBytes("c_blob", ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1, 2, 3)))); bs.setInt("pk", 42); session().execute(bs); // then String line = normalAppender.waitAndGet(10000); assertThat(line) .contains("Query completed normally") .contains(ipOfNode(1)) .contains("c_blob:0x0102" + TRUNCATED_OUTPUT) .doesNotContain("0x010203"); }
@Override public void write(JsonWriter writer, List<Byte> value) throws IOException { writer.value(base16().lowerCase().encode(Bytes.toArray(value))); }
@Override public byte[] getBytes() { final List<Byte> byteList = new ArrayList<>(); byteList.addAll(Bytes.asList(envelope, (byte) 0, (byte) 0, (byte) 0)); byteList.addAll(authorizedEnvelop.getBytes()); if (reservedEnvelop != null) byteList.addAll(reservedEnvelop.getBytes()); if (committedEnvelop != null) byteList.addAll(committedEnvelop.getBytes()); return Bytes.toArray(byteList); }
/** * Gets tlv body as byte array. * * @return tlv body as byte array */ public byte[] getTlvBodyAsByteArray() { List<Byte> bodyLst = new ArrayList<>(); bodyLst.addAll(Bytes.asList(this.routerAddress().toOctets())); return Bytes.toArray(bodyLst); }
public void testToArray_withNull() { List<Byte> list = Arrays.asList((byte) 0, (byte) 1, null); try { Bytes.toArray(list); fail(); } catch (NullPointerException expected) { } }
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 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)))); }
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)); }