If the output is closed before FastBufferedOutputStream is closed, then close() would throw because close() calls flush(), and it would try to write the buffer, even if there's nothing to write, and zero-length write() on a closed stream throws in some OutputStream implementations.
This can happen if the output is a socket, for example, that is managed separately from the output stream.
Fix by not calling write() from flush() at all if there is nothing to write.
If the buffer is not empty, then it would still try to write it, and would throw, which is probably correct.
If the output is closed before
FastBufferedOutputStream
is closed, thenclose()
would throw becauseclose()
callsflush()
, and it would try to write the buffer, even if there's nothing to write, and zero-lengthwrite()
on a closed stream throws in someOutputStream
implementations.This can happen if the output is a socket, for example, that is managed separately from the output stream.
Fix by not calling
write()
fromflush()
at all if there is nothing to write.If the buffer is not empty, then it would still try to write it, and would throw, which is probably correct.