com.jkristian.io
Class StringFilterInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.jkristian.io.FilteredByteInputStream
          extended by com.jkristian.io.FilteredCharInputStream
              extended by com.jkristian.io.StringFilterInputStream
All Implemented Interfaces:
java.io.Closeable

public class StringFilterInputStream
extends FilteredCharInputStream

A stream that gets input from a String, and optionally transforms it using filters.

This class is not thread-safe.


Field Summary
 
Fields inherited from class com.jkristian.io.FilteredByteInputStream
CHUNK_LENGTH
 
Constructor Summary
StringFilterInputStream(java.lang.String in)
          Create a stream that encodes characters using the default encoding.
StringFilterInputStream(java.lang.String in, int chunkLength)
          Create a stream that encodes characters using the default encoding.
StringFilterInputStream(java.lang.String in, java.lang.String encoding)
          Create a stream that encodes characters using the named encoding.
StringFilterInputStream(java.lang.String in, java.lang.String encoding, int chunkLength)
          Create a stream that encodes characters using the named encoding.
 
Method Summary
 void close()
           
protected  int filterInput()
          Copy data from the underlying String into the filter chain.
static void main(java.lang.String[] args)
          A unit test.
protected  boolean ready()
           
 
Methods inherited from class com.jkristian.io.FilteredCharInputStream
flush, getByteFilter, getCharFilter, setByteFilter, setCharFilter
 
Methods inherited from class com.jkristian.io.FilteredByteInputStream
available, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringFilterInputStream

public StringFilterInputStream(java.lang.String in)
Create a stream that encodes characters using the default encoding.

Parameters:
in - the String from which to read input characters

StringFilterInputStream

public StringFilterInputStream(java.lang.String in,
                               java.lang.String encoding)
                        throws java.io.UnsupportedEncodingException
Create a stream that encodes characters using the named encoding.

Parameters:
in - the String from which to read input characters
encoding - the name of a supported character encoding
Throws:
java.io.UnsupportedEncodingException

StringFilterInputStream

public StringFilterInputStream(java.lang.String in,
                               int chunkLength)
Create a stream that encodes characters using the default encoding.

Parameters:
in - the String from which to read input characters
chunkLength - the number of characters to process at a time

StringFilterInputStream

public StringFilterInputStream(java.lang.String in,
                               java.lang.String encoding,
                               int chunkLength)
                        throws java.io.UnsupportedEncodingException
Create a stream that encodes characters using the named encoding.

Parameters:
in - the String from which to read input characters
encoding - the name of a supported character encoding
chunkLength - the number of characters to process at a time
Throws:
java.io.UnsupportedEncodingException
Method Detail

close

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

ready

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

filterInput

protected int filterInput()
                   throws java.io.IOException
Copy data from the underlying String 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
A unit test. Echo the command line parameters to System.out.

Throws:
java.io.IOException