ClosedOutputStream#flush should throw (closes
MODIFY
src/main/java/org/apache/commons/io/output/ClosedOutputStream.java
src/main/java/org/apache/commons/io/output/ClosedOutputStream.java
@@ -47,4 +47,13 @@ public void write(final int b) throws IOException {
throw new IOException("write(" + b + ") failed: stream is closed");
}
+ /**
+ * Throws an {@link IOException} to indicate that the stream is closed.
+ *
+ * @throws IOException always thrown
+ */
+ @Override
+ public void flush() throws IOException {
+ throw new IOException("flush() failed: stream is closed");
+ }
}

MODIFY
src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java
src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java
@@ -41,4 +41,18 @@ public void testRead() throws Exception {
}
}
+ /**
+ * Test the <code>flush()</code> method.
+ * @throws Exception
+ */
+ @Test
+ public void testFlush() throws Exception {
+ try (ClosedOutputStream cos = new ClosedOutputStream()) {
+ cos.flush();
+ fail("flush()");
+ } catch (final IOException e) {
+ // expected
+ }
+ }
+
}

IO-546: ClosedOutputStream#flush should throw (closes #42)