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

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

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

ByteString.readFrom介绍

[英]Completely reads the given stream's bytes into a ByteString, blocking if necessary until all bytes are read through to the end of the stream. Performance notes: The returned ByteString is an immutable tree of byte arrays ("chunks") of the stream data. The first chunk is small, with subsequent chunks each being double the size, up to 8K. If the caller knows the precise length of the stream and wishes to avoid all unnecessary copies and allocations, consider using the two-argument version of this method, below.
[中]将给定流的字节完全读取到ByteString中,必要时阻塞,直到所有字节都被读取到流的末尾。性能说明:返回的ByteString是流数据的字节数组(“块”)的不可变树。第一个块很小,后续的块大小都是原来的两倍,最大为8K。如果调用方知道流的精确长度并希望避免所有不必要的拷贝和分配,请考虑下面的方法的两个参数版本。

代码示例

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

/**
 * Completely reads the given stream's bytes into a
 * {@code ByteString}, blocking if necessary until all bytes are
 * read through to the end of the stream.
 *
 * <b>Performance notes:</b> The returned {@code ByteString} is an
 * immutable tree of byte arrays ("chunks") of the stream data.  The
 * first chunk is small, with subsequent chunks each being double
 * the size, up to 8K.  If the caller knows the precise length of
 * the stream and wishes to avoid all unnecessary copies and
 * allocations, consider using the two-argument version of this
 * method, below.
 *
 * @param streamToDrain The source stream, which is read completely
 *     but not closed.
 * @return A new {@code ByteString} which is made up of chunks of
 *     various sizes, depending on the behavior of the underlying
 *     stream.
 * @throws IOException IOException is thrown if there is a problem
 *     reading the underlying stream.
 */
public static ByteString readFrom(InputStream streamToDrain)
  throws IOException {
 return readFrom(
   streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE);
}

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

/**
 * Completely reads the given stream's bytes into a
 * {@code ByteString}, blocking if necessary until all bytes are
 * read through to the end of the stream.
 *
 * <b>Performance notes:</b> The returned {@code ByteString} is an
 * immutable tree of byte arrays ("chunks") of the stream data.  The
 * first chunk is small, with subsequent chunks each being double
 * the size, up to 8K.
 *
 * <p>Each byte read from the input stream will be copied twice to ensure
 * that the resulting ByteString is truly immutable.
 *
 * @param streamToDrain The source stream, which is read completely
 *     but not closed.
 * @return A new {@code ByteString} which is made up of chunks of
 *     various sizes, depending on the behavior of the underlying
 *     stream.
 * @throws IOException IOException is thrown if there is a problem
 *     reading the underlying stream.
 */
public static ByteString readFrom(InputStream streamToDrain)
  throws IOException {
 return readFrom(streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE);
}

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

/**
 * Completely reads the given stream's bytes into a
 * {@code ByteString}, blocking if necessary until all bytes are
 * read through to the end of the stream.
 *
 * <b>Performance notes:</b> The returned {@code ByteString} is an
 * immutable tree of byte arrays ("chunks") of the stream data.  The
 * chunkSize parameter sets the size of these byte arrays.
 *
 * <p>Each byte read from the input stream will be copied twice to ensure
 * that the resulting ByteString is truly immutable.
 *
 * @param streamToDrain The source stream, which is read completely
 *     but not closed.
 * @param chunkSize The size of the chunks in which to read the
 *     stream.
 * @return A new {@code ByteString} which is made up of chunks of
 *     the given size.
 * @throws IOException IOException is thrown if there is a problem
 *     reading the underlying stream.
 */
public static ByteString readFrom(InputStream streamToDrain, int chunkSize)
  throws IOException {
 return readFrom(streamToDrain, chunkSize, chunkSize);
}

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

/**
 * Completely reads the given stream's bytes into a
 * {@code ByteString}, blocking if necessary until all bytes are
 * read through to the end of the stream.
 *
 * <b>Performance notes:</b> The returned {@code ByteString} is an
 * immutable tree of byte arrays ("chunks") of the stream data.  The
 * chunkSize parameter sets the size of these byte arrays. In
 * particular, if the chunkSize is precisely the same as the length
 * of the stream, unnecessary allocations and copies will be
 * avoided. Otherwise, the chunks will be of the given size, except
 * for the last chunk, which will be resized (via a reallocation and
 * copy) to contain the remainder of the stream.
 *
 * @param streamToDrain The source stream, which is read completely
 *     but not closed.
 * @param chunkSize The size of the chunks in which to read the
 *     stream.
 * @return A new {@code ByteString} which is made up of chunks of
 *     the given size.
 * @throws IOException IOException is thrown if there is a problem
 *     reading the underlying stream.
 */
public static ByteString readFrom(InputStream streamToDrain, int chunkSize)
  throws IOException {
 return readFrom(streamToDrain, chunkSize, chunkSize);
}

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

/**
 * Creates a {@code ByteArray} object given an {@link InputStream}. The stream is read into the
 * created object.
 */
public static final ByteArray copyFrom(InputStream input) throws IOException {
 return new ByteArray(ByteString.readFrom(input));
}

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

/**
 * Creates a buffer with data read from a file.
 */
@SuppressWarnings("Finally") // Not concerned about suppression; expected to be exceedingly rare
private ByteString createBufferFromFile(String fileClassPath) {
  ByteString buffer = ByteString.EMPTY;
  InputStream inputStream = getClass().getResourceAsStream(fileClassPath);
  if (inputStream == null) {
    throw new IllegalArgumentException("Unable to locate file on classpath: " + fileClassPath);
  }
  try {
    buffer = ByteString.readFrom(inputStream);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    try {
      inputStream.close();
    } catch (IOException ignorable) {
      // ignore
    }
  }
  return buffer;
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

ByteString contents = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

ByteString contents = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));

相关文章