本文整理汇总了Java中com.google.protobuf.ByteString.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java ByteString.toByteArray方法的具体用法?Java ByteString.toByteArray怎么用?Java ByteString.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ByteString
的用法示例。
在下文中一共展示了ByteString.toByteArray方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doMetaGetResponse
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
static GetResponse doMetaGetResponse(final SortedMap<byte [], Pair<HRegionInfo, ServerName>> meta,
final GetRequest request) {
ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
ByteString row = request.getGet().getRow();
Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray());
if (p == null) {
if (request.getGet().getClosestRowBefore()) {
byte [] bytes = row.toByteArray();
SortedMap<byte [], Pair<HRegionInfo, ServerName>> head =
bytes != null? meta.headMap(bytes): meta;
p = head == null? null: head.get(head.lastKey());
}
}
if (p != null) {
resultBuilder.addCell(getRegionInfo(row, p.getFirst()));
resultBuilder.addCell(getServer(row, p.getSecond()));
}
resultBuilder.addCell(getStartCode(row));
GetResponse.Builder builder = GetResponse.newBuilder();
builder.setResult(resultBuilder.build());
return builder.build();
}
示例2: convertUpdateIndexUseKryo
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public static int[] convertUpdateIndexUseKryo(ByteString neededColIndexes) {
Input input = new Input(neededColIndexes.toByteArray());
Kryo kryo = new Kryo();
kryo.register(Integer.class);
int size = kryo.readObject(input, Integer.class);
int[] ret = new int[size];
for (int i = 0; i < size; i++) {
ret[i] = kryo.readObject(input, Integer.class);
}
return ret;
}
示例3: testBuildPartitionResult
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
* testBuildPartitionResult
*/
public void testBuildPartitionResult() throws Exception {
Table catalog_tbl = this.getTable(TM1Constants.TABLENAME_SPECIAL_FACILITY);
VoltTable vt = CatalogUtil.getVoltTable(catalog_tbl);
assertNotNull(vt);
int num_rows = 50;
for (int i = 0; i < num_rows; i++) {
Object row[] = new Object[catalog_tbl.getColumns().size()];
for (int j = 0; j < row.length; j++) {
VoltType vtype = VoltType.get(catalog_tbl.getColumns().get(j).getType());
row[j] = VoltTypeUtil.getRandomValue(vtype, rand);
} // FOR
vt.addRow(row);
} // FOR
int dep_id = 10001;
DependencySet result = new DependencySet(new int[]{ dep_id }, new VoltTable[]{ vt });
RemoteTransaction ts = new RemoteTransaction(hstore_site);
WorkResult partitionResult = executor.buildWorkResult(ts, result, Status.OK, null);
assertNotNull(partitionResult);
assertEquals(result.size(), partitionResult.getDepDataCount());
assertEquals(1, partitionResult.getDepDataCount());
for (int i = 0; i < partitionResult.getDepDataCount(); i++) {
assertEquals(dep_id, partitionResult.getDepId(i));
ByteString bs = partitionResult.getDepData(i);
assertFalse(bs.isEmpty());
System.err.println("SIZE: " + StringUtil.md5sum(bs.asReadOnlyByteBuffer()));
byte serialized[] = bs.toByteArray();
VoltTable clone = FastDeserializer.deserialize(serialized, VoltTable.class);
assertNotNull(clone);
assertEquals(vt.getRowCount(), clone.getRowCount());
assertEquals(vt.getColumnCount(), clone.getColumnCount());
} // FOR
}
示例4: getPropertyValue
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
* Extracts an additional property byte value from a map with immutable ByteString values.
*/
@Nullable
public static byte[] getPropertyValue(
Map<String, ByteString> additionalProperties,
String key) {
ByteString value = additionalProperties.get(key);
if (value == null) {
return null;
}
return value.toByteArray();
}
示例5: decodeHashDataKey
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
private Pair<ByteString, ByteString> decodeHashDataKey(ByteString rawKey) {
checkArgument(
KeyUtils.hasPrefix(rawKey, ByteString.copyFrom(prefix)),
"invalid encoded hash data key prefix: " + new String(prefix));
CodecDataInput cdi = new CodecDataInput(rawKey.toByteArray());
cdi.skipBytes(prefix.length);
byte[] key = BytesType.readBytes(cdi);
long typeFlag = IntegerType.readULong(cdi);
if (typeFlag != HASH_DATA_FLAG) {
throw new TiClientInternalException("Invalid hash data flag: " + typeFlag);
}
byte[] field = BytesType.readBytes(cdi);
return Pair.create(ByteString.copyFrom(key), ByteString.copyFrom(field));
}
示例6: testDe
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Test
public void testDe() {
String msg = "brMcxcmVDxcd1IAs1z4LsXWXrZFfV+UBo37vcxL/NUY=";
ByteString b = ByteString.copyFromUtf8(msg);
byte[] o = b.toByteArray();
byte[] r = SecurityUtils.getInstance().DecryptMsg(o);
byte[] a =SecurityUtils.getInstance().EncryptMsg(new String(r));
//System.out.println(new String(r));
Assert.assertArrayEquals(o, a);
}
示例7: get
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Override
public byte[] get(byte[] k) {
ByteString key = ByteString.copyFrom(k);
ByteString bytes = cachedWrites.get(key);
if (bytes != null) {
// we haven't written these yet
return bytes.toByteArray();
}
TiKV.GetLocation keyLocation = tiKV.getKeyLocation(key);
Kvrpcpb.Context context = keyLocation.getContext();
RPC kvRPC = keyLocation.getKvRPC();
Kvrpcpb.CmdGetRequest.Builder getReq = Kvrpcpb.CmdGetRequest.newBuilder();
getReq.setKey(key);
if (timestamp == 0) {
timestamp = tiKV.getTimestamp();
}
getReq.setVersion(timestamp);
Msgpb.Message.Builder getMessage = Msgpb.Message.newBuilder();
getMessage.setMsgType(Msgpb.MessageType.KvReq);
Kvrpcpb.Request.Builder kvReq = Kvrpcpb.Request.newBuilder()
.setContext(context)
.setCmdGetReq(getReq)
.setType(Kvrpcpb.MessageType.CmdGet);
getMessage.setKvReq(kvReq);
Msgpb.Message getResponse = null;
try {
getResponse = kvRPC.send(getMessage.build());
Kvrpcpb.CmdGetResponse cmdGetResp = getResponse.getKvResp().getCmdGetResp();
Kvrpcpb.KeyError error = cmdGetResp.getError();
if (error != null) {
// Need to retry transactions that retryable / restart on abort
throw new TiException("Error getting key: " + error);
}
return cmdGetResp.getValue().toByteArray();
} catch (IOException e) {
throw new TiException("Failed to get key", e);
}
}
示例8: getBytesFromResponse
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
byte[] getBytesFromResponse(ByteString response) {
ByteBuffer bb = response.asReadOnlyByteBuffer();
bb.rewind();
byte[] bytes;
if (bb.hasArray()) {
bytes = bb.array();
} else {
bytes = response.toByteArray();
}
return bytes;
}
示例9: convert
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Override
public byte[] convert(ByteString value) {
return value.toByteArray();
}
示例10: getLatestSchemaVersion
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public long getLatestSchemaVersion() {
ByteString versionBytes = bytesGet(KEY_SCHEMA_VERSION);
CodecDataInput cdi = new CodecDataInput(versionBytes.toByteArray());
return Long.parseLong(new String(cdi.toByteArray(), StandardCharsets.UTF_8));
}
示例11: get
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public byte[] get(byte[] key) {
ByteString keyString = ByteString.copyFrom(key);
ByteString value = get(keyString);
return value.toByteArray();
}
示例12: CodecDataInput
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public CodecDataInput(ByteString data) {
this(data.toByteArray());
}
示例13: ByteStringToBytes
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public static byte[] ByteStringToBytes(ByteString byteString) {
return byteString == null ? null : byteString.toByteArray();
}
示例14: rollHLogWriter
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
* Roll the log writer. I.e. when using a file system based write ahead log,
* start writing log messages to a new file.
*
* Note that when talking to a version 1.0+ HBase deployment, the rolling is asynchronous.
* This method will return as soon as the roll is requested and the return value will
* always be null. Additionally, the named region server may schedule store flushes at the
* request of the wal handling the roll request.
*
* When talking to a 0.98 or older HBase deployment, the rolling is synchronous and the
* return value may be either null or a list of encoded region names.
*
* @param serverName
* The servername of the regionserver. A server name is made of host,
* port and startcode. This is mandatory. Here is an example:
* <code> host187.example.com,60020,1289493121758</code>
* @return a set of {@link HRegionInfo#getEncodedName()} that would allow the wal to
* clean up some underlying files. null if there's nothing to flush.
* @throws IOException if a remote or network exception occurs
* @throws FailedLogCloseException
* @deprecated use {@link #rollWALWriter(ServerName)}
*/
@Deprecated
public synchronized byte[][] rollHLogWriter(String serverName)
throws IOException, FailedLogCloseException {
ServerName sn = ServerName.valueOf(serverName);
final RollWALWriterResponse response = rollWALWriterImpl(sn);
int regionCount = response.getRegionToFlushCount();
if (0 == regionCount) {
return null;
}
byte[][] regionsToFlush = new byte[regionCount][];
for (int i = 0; i < regionCount; i++) {
ByteString region = response.getRegionToFlush(i);
regionsToFlush[i] = region.toByteArray();
}
return regionsToFlush;
}