edu.emory.mathcs.util.io
Class RedirectingReader

java.lang.Object
  extended byjava.io.Reader
      extended byjava.io.FilterReader
          extended byedu.emory.mathcs.util.io.RedirectingReader
All Implemented Interfaces:
RedirectibleReader

public class RedirectingReader
extends java.io.FilterReader
implements RedirectibleReader

Reader that supports redirecting data directly to a writer.

Version:
1.0
Author:
Dawid Kurzyniec
See Also:
RedirectingInputStream

Field Summary
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
RedirectingReader(java.io.Reader in)
          Creates a new redirecting reader that reads from the specified source with default autoflush and autoclose policies and a default buffer size of 2KB.
RedirectingReader(java.io.Reader in, boolean autoFlush, boolean autoClose)
          Creates a new redirecting reader that reads from the specified source, has specified autoflush and autoclose policy and a default buffer size of 2KB.
RedirectingReader(java.io.Reader in, boolean autoFlush, boolean autoClose, int len)
          Creates a new redirecting reader that reads from the specified source, has specified autoflush and autoclose policy, and a given buffer size.
RedirectingReader(java.io.Reader in, int len)
          Creates a new redirecting reader that reads from the specified source with default autoflush and autoclose policies and a specified buffer size.
 
Method Summary
 int redirect(java.io.Writer out, int len)
          Reads and redirects up to the len characters to a specified writer.
 int redirectAll(java.io.Writer out)
          Readirects all further data from this reader into the specified writer, until EOF.
 
Methods inherited from class java.io.FilterReader
close, mark, markSupported, read, read, ready, reset, skip
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RedirectingReader

public RedirectingReader(java.io.Reader in)
Creates a new redirecting reader that reads from the specified source with default autoflush and autoclose policies and a default buffer size of 2KB. The default autoflush policy is to flush the output after redirecting every chunk of data. The default autoclose policy is not to close the output upon EOF on the input during redirection.

Parameters:
in - the input to read from

RedirectingReader

public RedirectingReader(java.io.Reader in,
                         int len)
Creates a new redirecting reader that reads from the specified source with default autoflush and autoclose policies and a specified buffer size. The default autoflush policy is to flush the output after redirecting every chunk of data. The default autoclose policy is not to close the output upon EOF on the input during redirection. Buffer length is the maximum chunk size.

Parameters:
in - the input to read from
len - the maximum chunk size

RedirectingReader

public RedirectingReader(java.io.Reader in,
                         boolean autoFlush,
                         boolean autoClose)
Creates a new redirecting reader that reads from the specified source, has specified autoflush and autoclose policy and a default buffer size of 2KB. The autoFlush parameter decides whether the output should be automatically flushed after every chunk of redirected data. The autoClose parameter decides whether the output should be closed upon EOF on the input during redirection.

Parameters:
in - the input to read from
autoFlush - decides whether to flush the output after each redirect
autoClose - decides whether to close the output upon EOF on input during redirection

RedirectingReader

public RedirectingReader(java.io.Reader in,
                         boolean autoFlush,
                         boolean autoClose,
                         int len)
Creates a new redirecting reader that reads from the specified source, has specified autoflush and autoclose policy, and a given buffer size. The autoFlush parameter decides whether the output should be automatically flushed after every chunk of redirected data. The autoClose parameter decides whether the output should be closed upon EOF on the input during redirection. Buffer length is the maximum chunk size.

Parameters:
in - the input to read from
autoFlush - decides whether to flush the output after each redirect
autoClose - decides whether to close the output upon EOF on input during redirection
len - the maximum chunk size
Method Detail

redirect

public int redirect(java.io.Writer out,
                    int len)
             throws java.io.IOException
Description copied from interface: RedirectibleReader
Reads and redirects up to the len characters to a specified writer. Returns the number of characters actually redirected.

Specified by:
redirect in interface RedirectibleReader
Parameters:
out - the destination writer
len - the maximum number of characters to redirect
Returns:
number of characters actually redirected
Throws:
java.io.IOException - if I/O error occurs

redirectAll

public int redirectAll(java.io.Writer out)
                throws java.io.IOException
Description copied from interface: RedirectibleReader
Readirects all further data from this reader into the specified writer, until EOF. Returns the number of characters actually redirected.

Specified by:
redirectAll in interface RedirectibleReader
Parameters:
out - the destination writer
Returns:
number of characters actually redirected
Throws:
java.io.IOException - if I/O error occurs