/** * Copies the given bytes into a {@code ByteString}. * * @param bytes to copy * @return new {@code ByteString} */ public static ByteString copyFrom(byte[] bytes) { return copyFrom(bytes, 0, bytes.length); }
/** * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. */ @Deprecated public ByteString toByteString() { return ByteString.copyFrom(this.bytes, this.offset, this.length); }
/** * Copies the remaining bytes from a {@code java.nio.ByteBuffer} into * a {@code ByteString}. * * @param bytes sourceBuffer * @return new {@code ByteString} */ public static ByteString copyFrom(ByteBuffer bytes) { return copyFrom(bytes, bytes.remaining()); }
private ByteString getRangeEnd(final String key) { byte[] noPrefix = {0}; byte[] endKey = key.getBytes().clone(); for (int i = endKey.length - 1; i >= 0; i--) { if (endKey[i] < 0xff) { endKey[i] = (byte) (endKey[i] + 1); return ByteString.copyFrom(Arrays.copyOf(endKey, i + 1)); } } return ByteString.copyFrom(noPrefix); } }
/** * A wrapper of * {@link alluxio.proto.journal.Job.TaskInfo.Builder#setResult} to take byte[] as input. * * @param builder the builder to update * @param bytes results bytes to set * @return updated builder */ public static alluxio.proto.journal.Job.TaskInfo.Builder setResult( alluxio.proto.journal.Job.TaskInfo.Builder builder, byte[] bytes) { return builder.setResult(com.google.protobuf.ByteString.copyFrom(bytes)); }
/** * A wrapper of * {@link alluxio.proto.journal.Job.StartJobEntry.Builder#setSerializedJobConfig} * to take byte[] as input. * * @param builder the builder to update * @param bytes results bytes to set * @return updated builder */ public static alluxio.proto.journal.Job.StartJobEntry.Builder setSerializedJobConfig( alluxio.proto.journal.Job.StartJobEntry.Builder builder, byte[] bytes) { return builder.setSerializedJobConfig(com.google.protobuf.ByteString.copyFrom(bytes)); }
/** * Wraps a subset of a byte array in a {@link ByteString} without copying it. */ public static ByteString wrap(final byte[] array, int offset, int length) { return USE_ZEROCOPYBYTESTRING? HBaseZeroCopyByteString.wrap(array, offset, length): ByteString.copyFrom(array, offset, length); } }
/** * Wraps a byte array in a {@link ByteString} without copying it. */ public static ByteString wrap(final byte[] array) { return USE_ZEROCOPYBYTESTRING? HBaseZeroCopyByteString.wrap(array): ByteString.copyFrom(array); }
private ByteString getCredentials(Credentials credentials) throws IOException { ByteBuffer credentialsBinary = credentialMap.get(currentQueryIdentifierProto); if (credentialsBinary == null) { credentialsBinary = LlapTezUtils.serializeCredentials(credentials); credentialMap.putIfAbsent(currentQueryIdentifierProto, credentialsBinary.duplicate()); } else { credentialsBinary = credentialsBinary.duplicate(); } return ByteString.copyFrom(credentialsBinary); }
/** * Creates a byte string. Its size is the current size of this output * stream and its output has been copied to it. * * @return the current contents of this output stream, as a byte string. */ public synchronized ByteString toByteString() { flushLastBuffer(); return ByteString.copyFrom(flushedBuffers); }
@Override public long run(final JobConfig jobConfig) throws IOException { final ByteString jobConfigStr = ByteString.copyFrom(SerializationUtils.serialize(jobConfig)); return retryRPC(new RpcCallable<Long>() { public Long call() throws StatusRuntimeException { return mClient.run(RunPRequest.newBuilder().setJobConfig(jobConfigStr).build()).getJobId(); } }); } }
public static NetData.Certificate convert(PublicIdentityCertificate data) { return NetData.Certificate.newBuilder() .setId(data.getId()) .setModulus(ByteString.copyFrom(data.getModulus().toByteArray())) .setExponent(ByteString.copyFrom(data.getExponent().toByteArray())) .setSignature(ByteString.copyFrom(data.getSignatureBytes())).build(); }
@Override public PersistedData create(byte[] value) { return new ProtobufPersistedData(EntityData.Value.newBuilder().setBytes(ByteString.copyFrom(value)).build()); }
@Override public PersistedData create(ByteBuffer value) { return new ProtobufPersistedData(EntityData.Value.newBuilder().setBytes(ByteString.copyFrom(value)).build()); }
public static VProto.Versioned.Builder encodeVersioned(Versioned<byte[]> versioned) { return VProto.Versioned.newBuilder() .setValue(ByteString.copyFrom(versioned.getValue())) .setVersion(ProtoUtils.encodeClock(versioned.getVersion())); }
/** * @return proto representation of the task info * @throws IOException if serialization fails */ public alluxio.grpc.TaskInfo toProto() throws IOException { ByteBuffer result = mResult == null ? null : ByteBuffer.wrap(SerializationUtils.serialize(mResult)); alluxio.grpc.TaskInfo.Builder taskInfoBuilder = alluxio.grpc.TaskInfo.newBuilder().setJobId(mJobId).setTaskId(mTaskId) .setStatus(mStatus.toProto()).setErrorMessage(mErrorMessage); if (result != null) { taskInfoBuilder.setResult(ByteString.copyFrom(result)); } return taskInfoBuilder.build(); }
public void setRemoteAddress(ResolvableInetSocketAddress address) { final JournalMessages.RemoteAddress.Builder builder = msgBuilder.getRemoteBuilder(); builder.setAddress(ByteString.copyFrom(address.getAddressBytes())) .setPort(address.getPort()); // do not perform any reverse lookup here if (address.isReverseLookedUp()) { builder.setResolved(address.getHostName()); } }
private Map<byte[], SumResponse> sum(final Table table, final byte[] family, final byte[] qualifier, final byte[] start, final byte[] end) throws ServiceException, Throwable { ColumnAggregationProtos.SumRequest.Builder builder = ColumnAggregationProtos.SumRequest .newBuilder(); builder.setFamily(ByteString.copyFrom(family)); if (qualifier != null && qualifier.length > 0) { builder.setQualifier(ByteString.copyFrom(qualifier)); } return table.batchCoprocessorService( ColumnAggregationProtos.ColumnAggregationService.getDescriptor().findMethodByName("sum"), builder.build(), start, end, ColumnAggregationProtos.SumResponse.getDefaultInstance()); }
@Test public void bytes_field_can_not_be_converted() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("JSON format does not support type 'BYTE_STRING' of field 'bytesField'"); PrimitiveTypeMsg protobuf = PrimitiveTypeMsg.newBuilder() .setBytesField(ByteString.copyFrom(new byte[]{2, 4})) .build(); ProtobufJsonFormat.write(protobuf, JsonWriter.of(new StringWriter())); }
@Test public void testPersistBytes() throws Exception { ByteString bytes = ByteString.copyFrom(new byte[]{1, 2, 3, 4}); nameValueBuilder.setName(VALUE_NAME); nameValueBuilder.setValue(EntityData.Value.newBuilder().setBytes(bytes)); componentBuilder.addField(nameValueBuilder); entityBuilder.addComponent(componentBuilder.build()); worldBuilder.addEntity(entityBuilder.build()); EntityData.GlobalStore actual = persistAndRetrieve(worldBuilder.build()); assertEquals(VALUE_NAME, actual.getEntity(0).getComponent(0).getField(0).getName()); assertArrayEquals(bytes.toByteArray(), actual.getEntity(0).getComponent(0).getField(0).getValue().getBytes().toByteArray()); }