com.jkristian.io
Class InputFilterInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.jkristian.io.FilteredByteInputStream
          extended by com.jkristian.io.InputFilterInputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
Base64DecodeInputStream, Base64EncodeInputStream

public class InputFilterInputStream
extends FilteredByteInputStream

A filter that transforms input data using FilterOutputStream objects. This is helpful when you need to apply some kind of FilterOutputStream to input data (e.g. from a file or network connection). Without a helper class like this one, it would be necessary to implement a new kind of FilterInputStream that performs the same transformation.

read() returns a negative number (indicating the end of input) once for each time in.read() returns a negative number.

This class is not thread-safe.


Field Summary
 
Fields inherited from class com.jkristian.io.FilteredByteInputStream
CHUNK_LENGTH
 
Constructor Summary
InputFilterInputStream(java.io.InputStream in)
          Create a filter that encodes characters using the default encoding.
InputFilterInputStream(java.io.InputStream in, int chunkLength)
          Create a filter that encodes characters using the default encoding.
 
Method Summary
 void close()
           
protected  int filterInput()
          Copy data from the underlying input stream into the filter chain.
static void main(java.lang.String[] args)
          Copy System.in to System.out, base64 encoding and decoding it along the way.
protected  boolean ready()
           
 
Methods inherited from class com.jkristian.io.FilteredByteInputStream
available, flush, getByteFilter, mark, markSupported, read, read, read, reset, setByteFilter, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputFilterInputStream

public InputFilterInputStream(java.io.InputStream in)
Create a filter that encodes characters using the default encoding.

Parameters:
in - the stream from which to read input bytes

InputFilterInputStream

public InputFilterInputStream(java.io.InputStream in,
                              int chunkLength)
Create a filter that encodes characters using the default encoding.

Parameters:
in - the stream from which to read input bytes
chunkLength - the number of bytes to request in each call to in.read()
Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class FilteredByteInputStream
Throws:
java.io.IOException

ready

protected boolean ready()
                 throws java.io.IOException
Specified by:
ready in class FilteredByteInputStream
Returns:
true if some input is known to be available.
Throws:
java.io.IOException

filterInput

protected int filterInput()
                   throws java.io.IOException
Description copied from class: FilteredByteInputStream
Copy data from the underlying input stream into the filter chain.

Specified by:
filterInput in class FilteredByteInputStream
Returns:
a positive number if some input data were processed.
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Copy System.in to System.out, base64 encoding and decoding it along the way.

Throws:
java.io.IOException