请向我解释为什么Google编码人员不调用flush()方法?

  /**
  * Flushes the stream and forces any buffered bytes to be written.  This
  * does not flush the underlying OutputStream.
  */
  public void flush() throws IOException {
      if (output != null) {
          refreshBuffer();
      }
  }


有什么隐藏的原因吗?

最佳答案

因为您可能不想刷新基础流。例如,您可能只想刷新CodedOutputStream,以便可以安全地将一些其他数据写入基础OutputStream,并确保最终将其写入CodedOutputStream数据之后。在这种情况下,您可能还不想将数据写到基础文件或套接字中,因为批量处理数据效率更高。

10-04 11:49