Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The flush method of OutputStream does nothing?

From OutputStream.flush() docs.

Why does it state here in the doc that the flush method of OutputStream does nothing after explaining that it actually does something? Very confusing.

like image 863
Baz Avatar asked Dec 03 '12 15:12

Baz


People also ask

What does flush do OutputStream?

The flush() method of OutputStream class is used to flush the content of the buffer to the output stream. A buffer is a portion in memory that is used to store a stream of data(characters). That data sometimes will only get sent to an output device, when the buffer is full.

What does the flush () method of a stream do?

The Flush method is used when you need to send the contents of the Stream buffer to the associated underlying object. For example, a node or file represented by the URL that is the source of the Stream object. This will ensure that all changes made to the contents have been written.

What is flush method?

The flush() method of PrintWriter Class in Java is used to flush the stream. By flushing the stream, it means to clear the stream of any element that may be or maybe not inside the stream. It neither accepts any parameter nor returns any value.

Which method is used to flush the current stream?

The flush() method of PrintStream Class in Java is used to flush the stream.


2 Answers

OutputStream is an abstract class to be derived from. Subclasses will provide their own implementation if necessary. Otherwise the default behaviour is to do nothing.

e.g. see the code for ObjectOutputStream.flush()

like image 117
Brian Agnew Avatar answered Oct 25 '22 10:10

Brian Agnew


OutputStream is an abstract class. The deriving instance has to override that, if it needs a flush. For example the BufferedOutputStream.
Streams that have no buffer may not need to override flush().

like image 29
AlexWien Avatar answered Oct 25 '22 09:10

AlexWien