Java Code Examples for com.google.cloud.ByteArray#copyFrom()

The following examples show how to use com.google.cloud.ByteArray#copyFrom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudSpannerConversionUtilTest.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Test
public void testToCloudSpannerBytes() {
  byte[][] input = new byte[][] {"AA".getBytes(), "BB".getBytes()};
  List<ByteArray> output = CloudSpannerConversionUtil.toCloudSpannerBytes(input);
  ByteArray inp1 = ByteArray.copyFrom("AA".getBytes());
  ByteArray inp2 = ByteArray.copyFrom("BB".getBytes());
  assertArrayEquals(new ByteArray[] {inp1, inp2}, output.toArray());
}
 
Example 2
Source File: CloudSpannerConversionUtilTest.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Test
public void testToJavaByteArrays() {
  ByteArray inp1 = ByteArray.copyFrom("AA".getBytes());
  ByteArray inp2 = ByteArray.copyFrom("BB".getBytes());
  List<byte[]> output = CloudSpannerConversionUtil.toJavaByteArrays(Arrays.asList(inp1, inp2));

  List<byte[]> list = Arrays.asList("AA".getBytes(), "BB".getBytes());
  assertArrayEquals(list.toArray(), output.toArray());
}
 
Example 3
Source File: SpannerConvertersTest.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void bytesConversionTest() {
	ByteArray byteArray = ByteArray.copyFrom("some bytes");
	assertThat(SpannerConverters.JAVA_TO_SPANNER_BYTE_ARRAY_CONVERTER
			.convert(SpannerConverters.SPANNER_TO_JAVA_BYTE_ARRAY_CONVERTER.convert(byteArray)))
					.isEqualTo(byteArray);
}
 
Example 4
Source File: RandomValueGenerator.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
private ByteArray randomByteArray(Integer size) {
  size = size == -1 ? 20 : size;
  byte[] bytes = new byte[size];
  random.nextBytes(bytes);
  return ByteArray.copyFrom(bytes);
}
 
Example 5
Source File: SpannerConverters.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ByteArray convert(byte[] bytes) {
	return ByteArray.copyFrom(bytes);
}