src/java.base/share/classes/java/io/FilterOutputStream.java

Print this page

        

*** 46,55 **** --- 46,57 ---- /** * The underlying output stream to be filtered. */ protected OutputStream out; + private boolean closed; + /** * Creates an output stream filter built on top of the specified * underlying output stream. * * @param out the underlying output stream to be assigned to
*** 142,161 **** /** * Closes this output stream and releases any system resources * associated with the stream. * <p> ! * The <code>close</code> method of <code>FilterOutputStream</code> ! * calls its <code>flush</code> method, and then calls the ! * <code>close</code> method of its underlying output stream. * * @exception IOException if an I/O error occurs. * @see java.io.FilterOutputStream#flush() * @see java.io.FilterOutputStream#out */ @SuppressWarnings("try") public void close() throws IOException { try (OutputStream ostream = out) { flush(); } } } --- 144,166 ---- /** * Closes this output stream and releases any system resources * associated with the stream. * <p> ! * When not already closed, the {@code close} method of {@code ! * FilterOutputStream} calls its {@code flush} method, and then ! * calls the {@code close} method of its underlying output stream. * * @exception IOException if an I/O error occurs. * @see java.io.FilterOutputStream#flush() * @see java.io.FilterOutputStream#out */ @SuppressWarnings("try") public void close() throws IOException { + if (closed) + return; + closed = true; try (OutputStream ostream = out) { flush(); } } }