JDK-8196298: Add null Reader and Writer (original) (raw)

Claudia Reinhart claudia at reini.net
Sat Jan 27 08:43:41 UTC 2018


Hi there,

I saw that great extension on InputStream/OutputStream adding a Null implementation there. Based on those I would propose a similar addition to the Reader/Writer.

-Patrick

Here is what the API would look like based on the existing from InputStream/OutputStream:

    /**      * Returns a new {@code Reader} that contains no characters. The returned      * stream is initially open.  The stream is closed by calling the      * {@code close()} method.  Subsequent calls to {@code close()} have no      * effect.      *      *

While the stream is open, the {@code ready​()}, {@code read()},      * {@code read(char[])}, {@code read(char[], int, int)}, {@code skip()}, and      * {@code transferTo()} methods all behave as if end of stream has been      * reached.  After the stream has been closed, these methods all throw      * {@code IOException}.      *      *

The {@code markSupported()} method returns {@code false}.  The      * {@code mark()} method does nothing, and the {@code reset()} method      * throws {@code IOException}.      *      * @return an {@code Reader} which contains no characters      *      * @since 11      */     public static Reader nullReader() {}

    /**      * Returns a new {@code Writer} which discards all characters.  The      * returned stream is initially open.  The stream is closed by calling      * the {@code close()} method.  Subsequent calls to {@code close()} have      * no effect.      *      *

While the stream is open, the {@code write(int)}, {@code      * write(char[])}, and {@code write(char[], int, int)} methods do nothing.      * After the stream has been closed, these methods all throw {@code      * IOException}.      *      *

The {@code flush()} method does nothing.      *      * @return an {@code Writer} which discards all characters      *      * @since 11      */     public static Writer nullWriter() {}



More information about the core-libs-dev mailing list