Java 为什么是com.google.protobuf.codedOutStream';s方法刷新不';是否在内部调用output.flush()?

Java 为什么是com.google.protobuf.codedOutStream';s方法刷新不';是否在内部调用output.flush()?,java,protocol-buffers,Java,Protocol Buffers,请解释一下为什么谷歌程序员不调用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) { refreshBuf

请解释一下为什么谷歌程序员不调用
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
的数据之后。在这种情况下,您可能还不想将数据写入底层文件或套接字,因为批处理数据更有效。

他们为什么要调用它?refreshBuffer似乎起到了作用。您必须询问作者。在这种情况下,应该为此提供不同的方法。flush()刷新嵌套流:这是正常的期望。