The flush method of OutputStream does nothing?
Asked Answered
A

3

13

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.

Aborticide answered 3/12, 2012 at 15:22 Comment(0)
B
16

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()

Butterwort answered 3/12, 2012 at 15:24 Comment(2)
Resonable. But still a strange formulationin the documentation.Don
The reason it is in the documentation is that since the method itself is not abstract, developers who are implementing concrete instances of this class need to know what the base class does. I agree that for consumers of the interface, it is confusing.Phonon
S
2

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().

Spermiogenesis answered 3/12, 2012 at 15:25 Comment(4)
Doesn't have to. It can choose not toButterwort
Like all abstract classed can choose, too implement or not.Spermiogenesis
But you've said above, the deriving instance has to. That's the bit that I disagree with!Butterwort
public abstract void write(int b) Seems to be the only method of OutputStream that is not implemented. All the others have default implementations (even if they do nothing).Guessrope
C
0

The first part of the text is describing the general contract of flush. Classes which extend OutputStream are expected to adhere to this contract.

OutputStream is an abstract class, but a default implementation of flush is provided. As described, the implementation does nothing.

Crimmer answered 3/12, 2012 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.