本文整理汇总了Java中com.google.cloud.ByteArray类的典型用法代码示例。如果您正苦于以下问题:Java ByteArray类的具体用法?Java ByteArray怎么用?Java ByteArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteArray类属于com.google.cloud包,在下文中一共展示了ByteArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sizeOf
import com.google.cloud.ByteArray; //导入依赖的package包/类
private static long sizeOf(Key k) {
long result = 0;
for (Object part : k.getParts()) {
if (part == null) {
continue;
}
if (part instanceof Boolean) {
result += 1;
} else if (part instanceof Long) {
result += 8;
} else if (part instanceof Double) {
result += 8;
} else if (part instanceof String) {
result += ((String) part).length();
} else if (part instanceof ByteArray) {
result += ((ByteArray) part).length();
} else if (part instanceof Timestamp) {
result += 12;
} else if (part instanceof Date) {
result += 12;
}
}
return result;
}
示例2: bytes
import com.google.cloud.ByteArray; //导入依赖的package包/类
@Test
public void bytes() throws Exception {
Mutation empty =
Mutation.newInsertOrUpdateBuilder("test").set("one").to(ByteArray.fromBase64("")).build();
Mutation nullValue =
Mutation.newInsertOrUpdateBuilder("test").set("one").to((ByteArray) null).build();
Mutation sample =
Mutation.newInsertOrUpdateBuilder("test")
.set("one")
.to(ByteArray.fromBase64("abcdabcd"))
.build();
assertThat(MutationSizeEstimator.sizeOf(empty), is(0L));
assertThat(MutationSizeEstimator.sizeOf(nullValue), is(0L));
assertThat(MutationSizeEstimator.sizeOf(sample), is(6L));
}
示例3: testDeletes
import com.google.cloud.ByteArray; //导入依赖的package包/类
@Test
public void testDeletes() throws Exception {
encodeAndVerify(g(Mutation.delete("test", Key.of(1L))));
encodeAndVerify(g(Mutation.delete("test", Key.of((Long) null))));
KeySet allTypes = KeySet.newBuilder()
.addKey(Key.of(1L))
.addKey(Key.of((Long) null))
.addKey(Key.of(1.2))
.addKey(Key.of((Double) null))
.addKey(Key.of("one"))
.addKey(Key.of((String) null))
.addKey(Key.of(ByteArray.fromBase64("abcd")))
.addKey(Key.of((ByteArray) null))
.addKey(Key.of(Timestamp.now()))
.addKey(Key.of((Timestamp) null))
.addKey(Key.of(Date.fromYearMonthDay(2012, 1, 1)))
.addKey(Key.of((Date) null))
.build();
encodeAndVerify(g(Mutation.delete("test", allTypes)));
encodeAndVerify(
g(Mutation
.delete("test", KeySet.range(KeyRange.closedClosed(Key.of(1L), Key.of(2L))))));
}
示例4: toCloudSpannerBytes
import com.google.cloud.ByteArray; //导入依赖的package包/类
public static List<ByteArray> toCloudSpannerBytes(byte[][] bytes)
{
List<ByteArray> res = new ArrayList<>(bytes.length);
for (int index = 0; index < bytes.length; index++)
res.add(ByteArray.copyFrom(bytes[index]));
return res;
}
示例5: toJavaByteArrays
import com.google.cloud.ByteArray; //导入依赖的package包/类
public static List<byte[]> toJavaByteArrays(List<ByteArray> bytes)
{
List<byte[]> res = new ArrayList<>(bytes.size());
for (ByteArray ba : bytes)
res.add(ba.toByteArray());
return res;
}
示例6: testGetBytesIndex
import com.google.cloud.ByteArray; //导入依赖的package包/类
@Test
public void testGetBytesIndex() throws SQLException
{
assertNotNull(subject.getBytes(BYTES_COLINDEX_NOTNULL));
assertArrayEquals(ByteArray.copyFrom("BAR").toByteArray(), subject.getBytes(BYTES_COLINDEX_NOTNULL));
assertEquals(false, subject.wasNull());
assertNull(subject.getBytes(BYTES_COLINDEX_NULL));
assertTrue(subject.wasNull());
}
示例7: testGetBytesLabel
import com.google.cloud.ByteArray; //导入依赖的package包/类
@Test
public void testGetBytesLabel() throws SQLException
{
assertNotNull(subject.getBytes(BYTES_COL_NOT_NULL));
assertArrayEquals(ByteArray.copyFrom("FOO").toByteArray(), subject.getBytes(BYTES_COL_NOT_NULL));
assertEquals(false, subject.wasNull());
assertNull(subject.getBytes(BYTES_COL_NULL));
assertTrue(subject.wasNull());
}
示例8: testGetBinaryStreamIndex
import com.google.cloud.ByteArray; //导入依赖的package包/类
@Test
public void testGetBinaryStreamIndex() throws SQLException, IOException
{
assertNotNull(subject.getBinaryStream(BYTES_COLINDEX_NOTNULL));
InputStream actual = subject.getBinaryStream(BYTES_COLINDEX_NOTNULL);
byte[] cbuf = new byte[3];
int len = actual.read(cbuf, 0, cbuf.length);
assertArrayEquals(ByteArray.copyFrom("BAR").toByteArray(), cbuf);
assertEquals(3, len);
assertEquals(false, subject.wasNull());
assertNull(subject.getUnicodeStream(BYTES_COLINDEX_NULL));
assertTrue(subject.wasNull());
}
示例9: testGetBinaryStreamLabel
import com.google.cloud.ByteArray; //导入依赖的package包/类
@Test
public void testGetBinaryStreamLabel() throws SQLException, IOException
{
assertNotNull(subject.getBinaryStream(BYTES_COL_NOT_NULL));
InputStream actual = subject.getBinaryStream(BYTES_COL_NOT_NULL);
byte[] cbuf = new byte[3];
int len = actual.read(cbuf, 0, cbuf.length);
assertArrayEquals(ByteArray.copyFrom("FOO").toByteArray(), cbuf);
assertEquals(3, len);
assertEquals(false, subject.wasNull());
assertNull(subject.getUnicodeStream(BYTES_COL_NULL));
assertTrue(subject.wasNull());
}
示例10: assertSingleInsert
import com.google.cloud.ByteArray; //导入依赖的package包/类
private void assertSingleInsert(Mutation mutation, Mutation.Op operation)
{
Assert.assertNotNull(mutation);
Assert.assertEquals(operation, mutation.getOperation());
Assert.assertEquals("FOO", mutation.getTable());
List<String> columns = Lists.newArrayList(mutation.getColumns());
Assert.assertArrayEquals(new String[] { "COL1", "COL2", "COL3" }, columns.toArray());
Assert.assertArrayEquals(
new String[] { "1", "two", ByteArray.copyFrom(DatatypeConverter.parseHexBinary("aa")).toString() },
getValues(mutation.getValues()));
}
示例11: testToCloudSpannerBytes
import com.google.cloud.ByteArray; //导入依赖的package包/类
@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());
}
示例12: testToJavaByteArrays
import com.google.cloud.ByteArray; //导入依赖的package包/类
@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());
}
示例13: convert
import com.google.cloud.ByteArray; //导入依赖的package包/类
protected PubSubMessage convert(Message<?> message) throws Exception {
String encodedHeaders = encodeHeaders(message.getHeaders());
String topic = producerProperties.isPartitioned() ? topics
.get((Integer) message.getHeaders().get(BinderHeaders.PARTITION_HEADER))
.name() : topics.get(0).name();
PubSubMessage pubSubMessage = new PubSubMessage(
com.google.cloud.pubsub.Message
.builder(ByteArray.copyFrom((byte[]) message.getPayload()))
.addAttribute(PubSubBinder.SCST_HEADERS, encodedHeaders).build(),
topic);
return pubSubMessage;
}
开发者ID:viniciusccarvalho,项目名称:spring-cloud-stream-binder-pubsub,代码行数:13,代码来源:PubSubMessageHandler.java
示例14: encodePrimitive
import com.google.cloud.ByteArray; //导入依赖的package包/类
private void encodePrimitive(ByteArrayOutputStream bos, Value value) throws IOException {
switch (value.getType().getCode()) {
case BOOL:
bos.write(value.getBool() ? 1 : 0);
break;
case INT64:
VarInt.encode(value.getInt64(), bos);
break;
case FLOAT64:
new DataOutputStream(bos).writeDouble(value.getFloat64());
break;
case STRING: {
String str = value.getString();
VarInt.encode(str.length(), bos);
bos.write(str.getBytes(StandardCharsets.UTF_8));
break;
}
case BYTES: {
ByteArray bytes = value.getBytes();
VarInt.encode(bytes.length(), bos);
bos.write(bytes.toByteArray());
break;
}
case TIMESTAMP: {
Timestamp timestamp = value.getTimestamp();
VarInt.encode(timestamp.getSeconds(), bos);
VarInt.encode(timestamp.getNanos(), bos);
break;
}
case DATE: {
Date date = value.getDate();
VarInt.encode(encodeDate(date), bos);
break;
}
default:
throw new IllegalArgumentException("Unknown type " + value.getType());
}
}
示例15: estimateArrayValue
import com.google.cloud.ByteArray; //导入依赖的package包/类
private static long estimateArrayValue(Value v) {
switch (v.getType().getArrayElementType().getCode()) {
case BOOL:
return v.getBoolArray().size();
case INT64:
return 8 * v.getInt64Array().size();
case FLOAT64:
return 8 * v.getFloat64Array().size();
case STRING:
long totalLength = 0;
for (String s : v.getStringArray()) {
if (s == null) {
continue;
}
totalLength += s.length();
}
return totalLength;
case BYTES:
totalLength = 0;
for (ByteArray bytes : v.getBytesArray()) {
if (bytes == null) {
continue;
}
totalLength += bytes.length();
}
return totalLength;
case DATE:
return 12 * v.getDateArray().size();
case TIMESTAMP:
return 12 * v.getTimestampArray().size();
}
throw new IllegalArgumentException("Unsupported type " + v.getType());
}