Sharkysoft home

lava.io
Class FilteredInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--lava.io.FilteredInputStream

public abstract class FilteredInputStream
extends java.io.FilterInputStream

Removes characters from base input stream.

Details: FilteredInputStream is a FilterInputStream that accepts or rejects characters from the base input stream according to a specified criteria, on a per-character basis, passing on only accepted characters. The acceptance criteria is determined by the implementation of the accept method.

Example: The following program reads ASCII characters from System.in and outputs only the visible characters to System.out. Note how the accept method is overridden directly in the constructor call.

Since:
1999.04.14
Version:
1999.04.14
Author:
Sharky

Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
FilteredInputStream(java.io.InputStream in)
          Specifies base input stream.
 
Method Summary
protected abstract  boolean accept(int c)
          Defines acceptable characters.
 int read()
          Returns a filtered character.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteredInputStream

public FilteredInputStream(java.io.InputStream in)
Specifies base input stream.

Details: This constructor establishes in as the base input stream to be filtered.

Parameters:
in - the base input stream
Method Detail

read

public int read()
         throws java.io.IOException
Returns a filtered character.

Details: read consumes a character from the base input stream, testing its acceptability by passing it to the accept method, and then returning the character if it has been accepted. If the character is not accepted, read drops the character and tries the next character. This continues until an acceptable character is found or the EOS is reached. If the EOS is reached, read returns -1.

Overrides:
read in class java.io.FilterInputStream
Returns:
an acceptable character
Throws:
java.io.IOException - if an I/O error occurs

accept

protected abstract boolean accept(int c)
Defines acceptable characters.

Details: accept defines the behavior of this FilteredInputStream by determining whether characters should be accepted or rejected. accept returns true if the supplied character is acceptable, false otherwise.

Parameters:
c - the character
Returns:
true iff the character should be accepted

Sharkysoft home