Stephen Colebourne wrote:
public static void copyAndClose(final InputStream in,
        final OutputStream out)
        throws IOException {
    try {
        CopyUtils.copy(in, out);
        out.flush();

} finally {

IOUtils.copyAndClose(in); IOUtils.copyAndClose(out);

    }
}

I do not understand. What is being copied in the finally block? Should that have been:


    finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }

I do not want to swallow exceptions thrown by closing in or out as they might indicate to the caller some kind of important failure (say a network error). That is why my original has nexted try/finally blocks:

    finally {
        try {
            out.close();
        } finally {
            in.close();
        }
    }

Even so, this is quite a good suggestion. The main downside is that it doubles the number of methods. (CopyUtils is being deprecated, with the methods moving to IOUtils with better semantics and names to simplify the overall API)

Were you interested in writing the patch and tests for IOUtils?

Do I just pull IO from SVN? What form of patch: unified diff ok?


Cheers, --binkley

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to