Some common null objects for Java
Overview
This is a collection of null objects (i.e. implementations that do nothing) for the following use cases:
This library is hosted in the Maven Central Repository. You can use it with the following coordinates:
<dependency>
<groupId>net.markenwerk</groupId>
<artifactId>commons-nulls</artifactId>
<version>1.0.4</version>
</dependency>
Consult the usage description and Javadoc for further information.
Usage
InputStream and OutputStream
This library provides NullInputStream as a null implementation of an InputStream and NullOutputStream as a null implementation of an OutputStream.
// an InputStream that yields no bytes
InputStream in = new NullInputStream();
// an OutputStream that drops all bytes
OutputStream in = new NullOutputStream();
Reader and Writer
This library provides NullReader as a null implementation of a Reader and NullWriter as a null implementation of a Writer.
// an InputStream that yields no characters
Reader in = new NullReader();
// an OutputStream that drops all characters
Writer in = new NullWriter();