本文整理匯總了Java中com.google.protobuf.ByteString.concat方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteString.concat方法的具體用法?Java ByteString.concat怎麽用?Java ByteString.concat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.ByteString
的用法示例。
在下文中一共展示了ByteString.concat方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: readSpanningChunks
import com.google.protobuf.ByteString; //導入方法依賴的package包/類
@Test
public void readSpanningChunks() throws IOException {
ByteString hello = ByteString.copyFromUtf8("Hello, ");
ByteString world = ByteString.copyFromUtf8("World");
InputStream in = new ByteStringIteratorInputStream(
ImmutableList.<ByteString>of(hello, world).iterator());
ByteString helloWorld = hello.concat(world);
byte[] data = new byte[helloWorld.size()];
assertThat(in.read(data)).isEqualTo(helloWorld.size());
assertThat(ByteString.copyFrom(data)).isEqualTo(helloWorld);
assertThat(in.read()).isEqualTo(-1);
}
示例3: readSpanningChunksWithEmptyChunk
import com.google.protobuf.ByteString; //導入方法依賴的package包/類
@Test
public void readSpanningChunksWithEmptyChunk() throws IOException {
ByteString hello = ByteString.copyFromUtf8("Hello, ");
ByteString world = ByteString.copyFromUtf8("World");
InputStream in = new ByteStringIteratorInputStream(
ImmutableList.<ByteString>of(hello, ByteString.EMPTY, world).iterator());
ByteString helloWorld = hello.concat(world);
byte[] data = new byte[helloWorld.size()];
assertThat(in.read(data)).isEqualTo(helloWorld.size());
assertThat(ByteString.copyFrom(data)).isEqualTo(helloWorld);
assertThat(in.read()).isEqualTo(-1);
}
示例4: getNextKeyInByteOrder
import com.google.protobuf.ByteString; //導入方法依賴的package包/類
public static ByteString getNextKeyInByteOrder(ByteString key) {
return key.concat(ZERO_BYTE);
}
示例5: 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();
}