/** * Copy bytes from ByteString instance. * @param byteString copy from * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. */ @Deprecated public Bytes(final ByteString byteString) { this(byteString.toByteArray()); }
public byte[] getPayload() { return msgBuilder.getPayload().toByteArray(); // TODO PERFORMANCE array copy }
byte[] getBytesFromResponse(ByteString response) { ByteBuffer bb = response.asReadOnlyByteBuffer(); bb.rewind(); byte[] bytes; if (bb.hasArray()) { bytes = bb.array(); } else { bytes = response.toByteArray(); } return bytes; } }
@Override public Object deserialize(ByteString bytes) throws IOException, ClassNotFoundException { return BlobHelper.deserializeBlob(bytes.toByteArray()); } }
public static PublicIdentityCertificate convert(NetData.Certificate data) { return new PublicIdentityCertificate( data.getId(), new BigInteger(data.getModulus().toByteArray()), new BigInteger(data.getExponent().toByteArray()), new BigInteger(data.getSignature().toByteArray())); } }
@Override public BigDecimal getCellValueFromProto(BigDecimalMsg q) { return Bytes.toBigDecimal(q.getBigdecimalMsg().toByteArray()); } }
@Override public BigDecimal getPromotedValueFromProto(BigDecimalMsg r) { return Bytes.toBigDecimal(r.getBigdecimalMsg().toByteArray()); }
/** * Print out some subset of a MutationProto rather than all of it and its data * @param proto Protobuf to print out * @return Short String of mutation proto */ static String toShortString(final MutationProto proto) { return "row=" + Bytes.toString(proto.getRow().toByteArray()) + ", type=" + proto.getMutateType().toString(); }
/** * Converts a protobuf Token message back into a Token instance. * * @param proto the protobuf Token message * @return the Token instance */ public static Token<AuthenticationTokenIdentifier> toToken(AuthenticationProtos.Token proto) { return new Token<>( proto.hasIdentifier() ? proto.getIdentifier().toByteArray() : null, proto.hasPassword() ? proto.getPassword().toByteArray() : null, AuthenticationTokenIdentifier.AUTH_TOKEN_TYPE, proto.hasService() ? new Text(proto.getService().toStringUtf8()) : null); } }
@Override public void initialize(RowSwapProcessorRequest msg) { this.row1 = msg.getRow1().toByteArray(); this.row2 = msg.getRow2().toByteArray(); } }
@Override public void initialize(TimeoutProcessorRequest msg) throws IOException { this.row = msg.getRow().toByteArray(); } }
@Override public void initialize(FriendsOfFriendsProcessorRequest request) throws IOException { this.person = request.getPerson().toByteArray(); this.row = request.getRow().toByteArray(); result.clear(); result.addAll(request.getResultList()); } }
public static Cell toCell(ExtendedCellBuilder cellBuilder, final CellProtos.Cell cell) { return cellBuilder.clear() .setRow(cell.getRow().toByteArray()) .setFamily(cell.getFamily().toByteArray()) .setQualifier(cell.getQualifier().toByteArray()) .setTimestamp(cell.getTimestamp()) .setType((byte) cell.getCellType().getNumber()) .setValue(cell.getValue().toByteArray()) .build(); }
@Override public ProtobufMessageHandler getObjectFromMessage(byte[] message) throws IOException { Cell.Builder builder = Cell.newBuilder(); ProtobufUtil.mergeFrom(builder, message); setColumn(builder.getColumn().toByteArray()); setValue(builder.getData().toByteArray()); if (builder.hasTimestamp()) { setTimestamp(builder.getTimestamp()); } return this; }
@Override public void initialize(IncCounterProcessorRequest msg) { this.row = msg.getRow().toByteArray(); this.counter = msg.getCounter(); } }
@Override public byte[] getAsBytes() { if (data.hasBytes()) { return data.getBytes().toByteArray(); } else if (!isNull()) { throw new DeserializationException("Data is not bytes: " + data.toString()); } else { return new byte[0]; } }
public Event decrypt(Event cryptoEvent) { int keyIndex = keySelector.apply(cryptoEvent); if(keyIndex < 0) return cryptoEvent; return Event .newBuilder(cryptoEvent) .setPayload(SerializedObject .newBuilder(cryptoEvent.getPayload()) .setData(ByteString.copyFrom(decryptBytes(keyIndex, cryptoEvent.getPayload().getData().toByteArray()))) .build()) .build(); }
@Override public void channelRead0(ChannelHandlerContext ctx, LlapOutputSocketInitMessage msg) { String id = msg.getFragmentId(); byte[] tokenBytes = msg.hasToken() ? msg.getToken().toByteArray() : null; try { registerReader(ctx, id, tokenBytes); } catch (Throwable t) { // Make sure we fail the channel if something goes wrong. // We internally handle all the "expected" exceptions, so log a lot of information here. failChannel(ctx, id, StringUtils.stringifyException(t)); } }
@Override public void run(RunPRequest request, StreamObserver<RunPResponse> responseObserver) { RpcUtils.call(LOG, (RpcUtils.RpcCallableThrowsIOException<RunPResponse>) () -> { try { byte[] jobConfigBytes = request.getJobConfig().toByteArray(); return RunPResponse.newBuilder() .setJobId(mJobMaster.run((JobConfig) SerializationUtils.deserialize(jobConfigBytes))) .build(); } catch (ClassNotFoundException e) { throw new InvalidArgumentException(e); } }, "run", "request=%s", responseObserver, request); } }
@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()); }