The Apache Commons team has announced the release of Commons IO 2.0 which can be downloaded here.
Commons IO is a library that contains utility classes, stream implementations, file filters, file comparators and components for dealing with IO operations. The release notes contains the full details of the enhancements and bug fixes in IO 2.0, but below is a summary of whats new:
Java 5
Commons IO 2.0 has moved to JDK 1.5 allowing improvements both internally and in the external API. Except for the new minimum JDK requirement, however, it is otherwise backwards compatible with the previous release, which required JDK 1.3.
Streams, Readers & Writers
There are a number of new InputStream / Reader and OutputStream / Writer implementations in IO 2.0:
- BOMInputStream (and its associated ByteOrderMark) - wraps a stream and provides functionality to detect and/or exclude a Byte Order Mark.
- XmlStreamReader and XmlStreamWriter provide wrapper implementations that detect the encoding of XML documents
- ReaderInputStream and WriterOutputStream provide wrappers to convert from Readers/Writers to Input/OutputStreams - these implementations are typically used in situations where an existing API only accepts a stream, but where the stream contains character data that must be encoded/decoded for further use.
- TaggedInputStream and TaggedOutputStream provide a mechanism to tag an exception so that the stream causing it can be easily identified
- BoundedInputStream limits the bytes read from a stream
- StringBuilderWriter provides an un-synchronized alternative to StringWriter.
- BrokenInputStream and BrokenOutputStream can be used to test stream exception handling (all their methods throw an exception)
As well as these new streams the Proxy InputStream, OutputStream, Reader & Writer implementations have had exception handling and pre/post processing support added.
File Alteration Monitor
The File Alteration Monitor is a component for monitoring file system events (directory and file create, update and delete events). It originated in the JCI FAM module but has been refactored to improve performance and allow selective monitoring of the file system using filters. See the FileAlterationObserver JavaDocs for examples of how to use this component.
Tailer
The Tailer component is a simple implementation of the unix "tail -f" functionality. Register a TailerListener implementation to be notified of new lines in a file.
Utilities
-
New
skipFully()
methods for InputStreams and Readers -
A new
toBufferedInputStream()
method that avoids unnecessary array allocation/copy -
A new
isSymlink()
method to detect sym links -
A new
sizeOf(File)
method which, if the file is a directory, sums the sizes of the files recursively -
New methods for getting the system's home directory file or path
-
New methods for getting the system's temporary directory file or path
-
New flavours of the
normalize()
andnormalizeNoEndSeparator()
methods where the separator can be specified -
New implementation of the
freeSpaceKb()
method that has no arguments -
New implementations of the
freeSpaceKb()
methods that take a timeout parameter
Comparators
- All the comparator implementations now include convenience methods for sorting lists or arrays
- A new CompositeFileComparator implementation has been added which allows two or more file comparators to be combined
- A new DirectoryFileComparator implementation has been added which compares files based on whether a file is a directory or not
File Filters
-
A new Magic Number file filter has been added which matches files containing a "magic number"
-
FileFilterUtils has the following additions:
-
New methods for creating name, prefix and suffix filters whether the case sensitivity is specified.
-
New methods to filter arrays, lists and sets
-
New varargs methods for creating AndFileFilter and OrFileFilter instances