Filter Streams Java

Filter Streams Java


Filter Streams Java

Character Filter Streams

In this category, two streams exist – FilterReader and FilterWriter. Filter streams are concrete classes that include some filtering capabilities as data is read or written by another stream. For example, a FilterReader object takes input from another Reader object and does processing for extra functionality and returns the processed data. A number of filter streams can be chained as one unit of a large filter which can ultimately turn out to a big processing.

class FilterReader

It is an abstract class of character streams with filter capabilities on reading-side. Its equivalent in byte streams is FilterInputStream. It includes only one subclass, PushbackReader. Using PushbackReader is similar to PushbackInputStream.

Following is the class signature

public class FilterReader extends Reader

class FilterWriter

FilterWriter is an abstract filter class for writing character data. Its equivalent on byte streams is FilterOutputStream. It does not have any subclasses.

Following is the class signature

public abstract class FilterWriter extends Writer

For a program on FileReader and FileWriter, refer Byte streams vs Character streams.

3 thoughts on “Filter Streams Java

  1. Mara A

    The word filter is derived by analogy from a water filter. A water filter sits between the pipe
    and faucet, pulling out impurities. A stream filter sits between the source of the data and its
    eventual destination and applies a specific algorithm to the data. As drops of water are passed
    through the water filter and modified, so too are bytes of data passed through the stream filter.
    Of course, there are some big differences—most notably, a stream filter can add data or some
    other kind of annotation to the stream, in addition to removing things you don’t want; it may
    even produce a stream that is completely different from its original input (for example, by
    compressing the original data).

Leave a Reply

Your email address will not be published. Required fields are marked *