本文整理汇总了Java中com.google.protobuf.ByteString.substring方法的典型用法代码示例。如果您正苦于以下问题:Java ByteString.substring方法的具体用法?Java ByteString.substring怎么用?Java ByteString.substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ByteString
的用法示例。
在下文中一共展示了ByteString.substring方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shiftByStatus
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
private static ByteString shiftByStatus(ByteString v, Status s) {
switch (s) {
case EQUAL:
return v;
case LESS:
return v.substring(0, v.size() - 1);
case GREATER:
return v.concat(ByteString.copyFrom(new byte[] {1, 0}));
default:
throw new IllegalArgumentException("Only EQUAL,LESS,GREATER allowed");
}
}
示例2: readBlob
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
private void readBlob(
ReadRequest request,
StreamObserver<ReadResponse> responseObserver) {
String resourceName = request.getResourceName();
Instance instance;
try {
instance = instances.getFromBlob(resourceName);
} catch (InstanceNotFoundException ex) {
responseObserver.onError(BuildFarmInstances.toStatusException(ex));
return;
}
Digest digest = UrlPath.parseBlobDigest(resourceName);
ByteString blob = instance.getBlob(
digest, request.getReadOffset(), request.getReadLimit());
if (blob == null) {
responseObserver.onError(new StatusException(Status.NOT_FOUND));
return;
}
while (!blob.isEmpty()) {
ByteString chunk;
if (blob.size() < DEFAULT_CHUNK_SIZE) {
chunk = blob;
blob = ByteString.EMPTY;
} else {
chunk = blob.substring(0, (int) DEFAULT_CHUNK_SIZE);
blob = blob.substring((int) DEFAULT_CHUNK_SIZE);
}
responseObserver.onNext(ReadResponse.newBuilder()
.setData(chunk)
.build());
}
responseObserver.onCompleted();
}
示例3: split
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public static List<Coprocessor.KeyRange> split(Coprocessor.KeyRange range, int splitFactor) {
if (splitFactor > 32 || splitFactor <= 0 || (splitFactor & (splitFactor - 1)) != 0) {
throw new TiClientInternalException(
"splitFactor must be positive integer power of 2 and no greater than 16");
}
ByteString startKey = range.getStart();
ByteString endKey = range.getEnd();
// we don't cut infinite
if (startKey.isEmpty() || endKey.isEmpty()) {
return ImmutableList.of(range);
}
ImmutableList.Builder<Coprocessor.KeyRange> resultList = ImmutableList.builder();
int maxSize = Math.max(startKey.size(), endKey.size());
int i;
for (i = 0; i < maxSize; i++) {
byte sb = i < startKey.size() ? startKey.byteAt(i) : 0;
byte eb = i < endKey.size() ? endKey.byteAt(i) : 0;
if (sb != eb) {
break;
}
}
ByteString sRemaining = i < startKey.size() ? startKey.substring(i) : ByteString.EMPTY;
ByteString eRemaining = i < endKey.size() ? endKey.substring(i) : ByteString.EMPTY;
CodecDataInput cdi = new CodecDataInput(sRemaining);
int uss = cdi.readPartialUnsignedShort();
cdi = new CodecDataInput(eRemaining);
int ues = cdi.readPartialUnsignedShort();
int delta = (ues - uss) / splitFactor;
if (delta <= 0) {
return ImmutableList.of(range);
}
ByteString prefix = startKey.size() > endKey.size() ?
startKey.substring(0, i) : endKey.substring(0, i);
ByteString newStartKey = startKey;
ByteString newEndKey;
for (int j = 0; j < splitFactor; j++) {
uss += delta;
if (j == splitFactor - 1) {
newEndKey = endKey;
} else {
CodecDataOutput cdo = new CodecDataOutput();
cdo.writeShort(uss);
newEndKey = prefix.concat(cdo.toByteString());
}
resultList.add(makeCoprocRange(newStartKey, newEndKey));
newStartKey = newEndKey;
}
return resultList.build();
}