Name
FilterWriter
Synopsis
This
abstract class is intended to act as a superclass for character
output streams that filter the data written to them before writing it
to some other character output stream.
FilterWriter
is declared
abstract
so that it cannot be instantiated. But
none of its methods are themselves abstract: they all simply invoke
the corresponding method on the output stream that was passed to the
FilterWriter
constructor. If you were allowed to
instantiate a FilterWriter
object,
you’d find that it acts as a null filter (i.e., it
simply passes the characters written to it along, without any
filtration).
Because FilterWriter
implements a null filter, it
is an ideal superclass for classes that want to implement simple
filters without having to override all of the methods of
Writer
. In order to create your own filtered
character output stream, you should subclass
FilterWriter
and
override all its write( )
methods to perform the
desired filtering operation. Note that you can implement two of the
write( )
methods in terms of the third and thus
implement your filtering algorithm only once. In some cases, you may
want to override other Writer
methods and add
other methods or constructors that are specific to your subclass.
FilterWriter
is the character-stream analog of
FilterOutputStream
.
Figure 9-24. java.io.FilterWriter
public abstract class FilterWriter extends Writer { // ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.