Why doesn't the com.google.protobuf.CodedOutputStream flush method call output.flush () inside?

Explain to me why Google coders do not name the method 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();
      }
  }

Are there any hidden reasons for this?

+3
source share
1 answer

Because you may not want to clear the underlying thread. For example, you may only need to clear CodedOutputStreamit so that you can safely write some other data to the base OutputStreamand make sure that it ends after the data CodedOutputStream. In this case, you may not want to write data to a base file or socket, because it is more efficient for batch processing data.

0
source

All Articles