Classes for IO
Saturday, April 19, 2014 at 9:13PM
Chris

Jadira 3.2.0.GA will introduce some new classes for IO as part of a jadira-lang module. See JDF-77.

These address adapting NIO and traditional Java IO streams, optimised Buffered Stream inplementations, and an extension of the SAX InputSource that supports a variety of Source providers including the Spring Resource abstraction.

IO2NIO

This package provides two classes. ByteBufferBackedOutputStream is a custom OutputStream that writes to a ByteBuffer. ByteBufferBackedInputStream exposes reading from a ByteBuffer via an InputStream.

Core

I have frequently had the need to create similar classes to this one, so its well overdue to include it into Jadira. The class is a subclass of SAXInputSource. Its key feature is the variety of types from which the InputSource can be constructed - constructors are provided for File, InputStream, InputStreamSource, Resource (from Spring Framework) and URL.

Buffered

This package provides classes intended to be be used as an alternative to BufferedInputStream and BufferedOutputStream. Unlike those JDK classes they do not provide synchronization of their methods.

The following classes are provided for InputStream capabilities:

AbstractBufferedInputStream provides base functionality. It recreates some functionality from BufferedInputStream, but is organised to facilitate extendability. Whilst it does not subclass BufferedInputStream it instead subclasses FilterInputStream (the superclass of BufferedInputStream), so can be used in many of the same places.

Three subclasses exist, these are backed by DirectByteBuffer, ByteBuffer and a byte array respectively.

For OutputStream, equivalent buffered classes are provided with similar properties:

Article originally appeared on Jadira (http://blog.jadira.co.uk/).
See website for complete article licensing information.