3

请解释一下为什么谷歌编码器不调用该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();
      }
  }

这有什么隐藏的原因吗?

4

1 回答 1

0

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

于 2013-09-19T23:29:46.090 回答