Hi Huxing, since the PrintStream/PrintWriter are built around an existing (open) OutputStream/Writer: the parameter passed to the method, it is the responsibility of the caller to close the OutputStream/Writer.
Thus, there is no need to close the PrintStream/PrintWriter (they would close the underlying OutputStream/Writer, which is not what would be expected when the method is called). Regards, Julien 2010/10/25 Zhang, Huxing <huxing.zh...@intel.com>: > Dear Apache Commons IO developers, > I found there might be a close method missing in the source code of test > cases, which may be an issue. > No patch seems to be applied till revision 1026932. > How do you guys think? > > The original code here is: > In > io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java > Line 203-223 (revision 1026932) > > protected void checkWrite(OutputStream output) throws Exception { > try { > new java.io.PrintStream(output).write(0); > } catch (Throwable t) { > throw new AssertionFailedError( > "The copy() method closed the stream " > + "when it shouldn't have. " > + t.getMessage()); > } > } > > protected void checkWrite(Writer output) throws Exception { > try { > new java.io.PrintWriter(output).write('a'); > } catch (Throwable t) { > throw new AssertionFailedError( > "The copy() method closed the stream " > + "when it shouldn't have. " > + t.getMessage()); > } > } > > The java.io.PrintWriter is initialized without being closed after use. So > does the java.io.PrintStream instance. > > Thanks &Best regards, > Huxing > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org