com.google.protobuf.ByteString.substring()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中com.google.protobuf.ByteString.substring()方法的一些代码示例,展示了ByteString.substring()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.substring()方法的具体详情如下:
包路径:com.google.protobuf.ByteString
类名称:ByteString
方法名:substring

ByteString.substring介绍

[英]Return the substring from beginIndex, inclusive, to the end of the string.
[中]将子字符串从beginIndex(含)返回到字符串的末尾。

代码示例

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Return the substring from {@code beginIndex}, inclusive, to the end of the
 * string.
 *
 * @param beginIndex start at this index
 * @return substring sharing underlying data
 * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
 *     {@code beginIndex > size()}.
 */
public final ByteString substring(int beginIndex) {
 return substring(beginIndex, size());
}

代码示例来源:origin: osmandapp/Osmand

/**
 * Return the substring from {@code beginIndex}, inclusive, to the end of the
 * string.
 *
 * @param beginIndex start at this index
 * @return substring sharing underlying data
 * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
 *     {@code beginIndex > size()}.
 */
public ByteString substring(int beginIndex) {
 return substring(beginIndex, size());
}

代码示例来源:origin: com.google.protobuf/protobuf-java

@Override
boolean equalsRange(ByteString other, int offset, int length) {
 return substring(0, length).equals(other.substring(offset, offset + length));
}

代码示例来源:origin: com.google.protobuf/protobuf-java

return left.substring(beginIndex, endIndex);
 return right.substring(beginIndex - leftLength, endIndex - leftLength);
ByteString leftSub = left.substring(beginIndex);
ByteString rightSub = right.substring(0, endIndex - leftLength);

代码示例来源:origin: osmandapp/Osmand

result = left.substring(beginIndex, endIndex);
} else if (beginIndex >= leftLength) {
   .substring(beginIndex - leftLength, endIndex - leftLength);
} else {
 ByteString leftSub = left.substring(beginIndex);
 ByteString rightSub = right.substring(0, endIndex - leftLength);

代码示例来源:origin: osmandapp/Osmand

/**
 * Tests if this bytestring starts with the specified prefix.
 * Similar to {@link String#startsWith(String)}
 *
 * @param prefix the prefix.
 * @return <code>true</code> if the byte sequence represented by the
 *         argument is a prefix of the byte sequence represented by
 *         this string; <code>false</code> otherwise.
 */
public boolean startsWith(ByteString prefix) {
 return size() >= prefix.size() &&
     substring(0, prefix.size()).equals(prefix);
}

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Tests if this bytestring starts with the specified prefix.
 * Similar to {@link String#startsWith(String)}
 *
 * @param prefix the prefix.
 * @return <code>true</code> if the byte sequence represented by the
 *         argument is a prefix of the byte sequence represented by
 *         this string; <code>false</code> otherwise.
 */
public final boolean startsWith(ByteString prefix) {
 return size() >= prefix.size() &&
     substring(0, prefix.size()).equals(prefix);
}

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Tests if this bytestring ends with the specified suffix.
 * Similar to {@link String#endsWith(String)}
 *
 * @param suffix the suffix.
 * @return <code>true</code> if the byte sequence represented by the
 *         argument is a suffix of the byte sequence represented by
 *         this string; <code>false</code> otherwise.
 */
public final boolean endsWith(ByteString suffix) {
 return size() >= suffix.size() &&
   substring(size() - suffix.size()).equals(suffix);
}

代码示例来源:origin: com.google.protobuf/protobuf-java

return other.substring(offset, offset + length).equals(substring(0, length));

代码示例来源:origin: line/armeria

/**
 * Generates a payload of desired type and size. Reads compressableBuffer or
 * uncompressableBuffer as a circular buffer.
 */
private ByteString generatePayload(ByteString dataBuffer, int offset, int size) {
  ByteString payload = ByteString.EMPTY;
  // This offset would never pass the array boundary.
  int begin = offset;
  int end = 0;
  int bytesLeft = size;
  while (bytesLeft > 0) {
    end = Math.min(begin + bytesLeft, dataBuffer.size());
    // ByteString.substring returns the substring from begin, inclusive, to end, exclusive.
    payload = payload.concat(dataBuffer.substring(begin, end));
    bytesLeft -= (end - begin);
    begin = end % dataBuffer.size();
  }
  return payload;
}

代码示例来源:origin: googleapis/google-cloud-java

public static ByteStringRange prefix(ByteString prefix) {
 if (prefix.isEmpty()) {
  return unbounded();
 }
 int offset = prefix.size() - 1;
 int curByte = 0xFF;
 while (offset >= 0) {
  curByte = prefix.byteAt(offset) & 0xFF;
  if (curByte != 0xFF) {
   break;
  }
  offset--;
 }
 if (offset < 0) {
  // We got an 0xFFFF... (only FFs) stopRow value which is
  // the last possible prefix before the end of the table.
  // So set it to stop at the 'end of the table'
  return unbounded().startClosed(prefix);
 }
 ByteString endPrefix = offset == 0 ? ByteString.EMPTY : prefix.substring(0, offset);
 ByteString endSuffix = UnsafeByteOperations.unsafeWrap(new byte[] {(byte) (curByte + 1)});
 ByteString end = endPrefix.concat(endSuffix);
 ByteStringRange range = ByteStringRange.unbounded().startClosed(prefix);
 if (!end.isEmpty()) {
  range.endOpen(end);
 }
 return range;
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
 * List of ByteStrings that encode this block report
 *
 * @return ByteStrings
 */
public List<ByteString> getBlocksBuffers() {
 final ByteString blocksBuf = getBlocksBuffer();
 final List<ByteString> buffers;
 final int size = blocksBuf.size();
 if (size <= CHUNK_SIZE) {
  buffers = Collections.singletonList(blocksBuf);
 } else {
  buffers = new ArrayList<ByteString>();
  for (int pos=0; pos < size; pos += CHUNK_SIZE) {
   // this doesn't actually copy the data
   buffers.add(blocksBuf.substring(pos, Math.min(pos+CHUNK_SIZE, size)));
  }
 }
 return buffers;
}

代码示例来源:origin: com.google.protobuf/protobuf-lite

/**
 * Return the substring from {@code beginIndex}, inclusive, to the end of the
 * string.
 *
 * @param beginIndex start at this index
 * @return substring sharing underlying data
 * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
 *     {@code beginIndex > size()}.
 */
public final ByteString substring(int beginIndex) {
 return substring(beginIndex, size());
}

代码示例来源:origin: yeriomin/play-store-api

/**
 * Return the substring from {@code beginIndex}, inclusive, to the end of the
 * string.
 *
 * @param beginIndex start at this index
 * @return substring sharing underlying data
 * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
 *     {@code beginIndex > size()}.
 */
public final ByteString substring(int beginIndex) {
 return substring(beginIndex, size());
}

代码示例来源:origin: com.google.protobuf/protobuf-lite

@Override
boolean equalsRange(ByteString other, int offset, int length) {
 return substring(0, length).equals(other.substring(offset, offset + length));
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

/**
 * Return the substring from {@code beginIndex}, inclusive, to the end of the
 * string.
 *
 * @param beginIndex start at this index
 * @return substring sharing underlying data
 * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
 *     {@code beginIndex > size()}.
 */
public ByteString substring(int beginIndex) {
 return substring(beginIndex, size());
}

代码示例来源:origin: tronprotocol/wallet-cli

public static String getBase64FromByteString(ByteString sign) {
 byte[] r = sign.substring(0, 32).toByteArray();
 byte[] s = sign.substring(32, 64).toByteArray();
 byte v = sign.byteAt(64);
 if (v < 27) {
  v += 27; //revId -> v
 }
 ECDSASignature signature = ECDSASignature.fromComponents(r, s, v);
 return signature.toBase64();
}

代码示例来源:origin: com.google.protobuf/protobuf-lite

/**
 * Tests if this bytestring starts with the specified prefix.
 * Similar to {@link String#startsWith(String)}
 *
 * @param prefix the prefix.
 * @return <code>true</code> if the byte sequence represented by the
 *         argument is a prefix of the byte sequence represented by
 *         this string; <code>false</code> otherwise.
 */
public final boolean startsWith(ByteString prefix) {
 return size() >= prefix.size() &&
     substring(0, prefix.size()).equals(prefix);
}

代码示例来源:origin: com.google.protobuf/protobuf-lite

/**
 * Tests if this bytestring ends with the specified suffix.
 * Similar to {@link String#endsWith(String)}
 *
 * @param suffix the suffix.
 * @return <code>true</code> if the byte sequence represented by the
 *         argument is a suffix of the byte sequence represented by
 *         this string; <code>false</code> otherwise.
 */
public final boolean endsWith(ByteString suffix) {
 return size() >= suffix.size() &&
   substring(size() - suffix.size()).equals(suffix);
}

代码示例来源:origin: horrorho/LiquidDonkey

ByteString checksum(byte[] data) {
    byte[] hash = new byte[digest.getDigestSize()];
    byte[] hashHash = new byte[digest.getDigestSize()];

    digest.reset();
    digest.update(data, 0, data.length);
    digest.doFinal(hash, 0);
    digest.update(hash, 0, hash.length);
    digest.doFinal(hashHash, 0);

    return ByteString.copyFrom(hashHash).substring(0, 20);
  }
}

相关文章