FilterOutputStream.close() throws exception from flush()

Alex Lam S.L. alexlamsl at gmail.com
Fri Feb 10 14:34:12 UTC 2012


It is a custom OutputStream class which is not part of the JDK.

In this case close() is being called multiple times, because there are
actions which relies it. And flush() will throw IOException if the
stream is already closed.

I guess I can work around this by introducing a boolean flag to track
if FilterOutp​utStream.close() has been called in the past and avoid
calling it again, but it is not the best solution IMHO.


Alex.


On Fri, Feb 10, 2012 at 2:15 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 10/02/2012 13:52, Alex Lam S.L. wrote:
>>
>> Hi there,
>>
>> Thanks for the pointer - I wasn't able to trace back to that email for
>> some reasons.
>>
>> The problem is that:
>>
>>  - flush() is reporting IOException because underlying stream is closed
>>  - close() is then forwarding that IOException now in JavaSE 8
>>
>> I guess my question is: what is the best way to check and avoid the
>> case where OutputStream is already closed?
>>
> Do you know what the type of the underlying stream is? Clearly flush should
> fail if there are bytes to flush and the stream is open. Whether calling
> flush on a closed stream should fail or not isn't clear from the javadoc.
>
> -Alan
>



More information about the core-libs-dev mailing list