Wednesday, December 08, 2010

Apache Commons IO 2.0

Congrats to the Apache Commons IO Team on the release of the 2.0 framework. It has been a long time coming. The latest libraries require Java 1.5 which is a quantum jump in Apache terms. The old library required Java 1.3.

The IOUtils class provides a number of convenience methods to handle most IO operations. One of my favorite methods is IOUtils.copy(InputStream input, OutputStream output). A simple method, but so very useful since it is so common.

Have you ever needed to create unit tests on methods which require a closed InputStream, or OutputStream. I am sure you have, if not you just have not gotten there yet. Apache Commons IO offers you ClosedInputStream and ClosedOutputStream.

There are some other nice classes especially for debugging like CountingInputStream and CountingOutputStream which records the number of bytes read, or written. I can see another use for cloud computing models where you are charged for data transfers. This can help you keep track of those numbers for comparison with your charges.

If you have not taken the time to look at these great tools, take a couple of minutes to just look at the javadocs. I am sure you will be impressed like me.
Enhanced by Zemanta


Popular Posts