com.armatiek.infofuze.stream
Class AutoCloseReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.FilterReader
          extended by org.apache.commons.io.input.ProxyReader
              extended by com.armatiek.infofuze.stream.AutoCloseReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class AutoCloseReader
extends org.apache.commons.io.input.ProxyReader

Proxy reader that closes and discards the underlying reader as soon as the end of input has been reached or when the reader is explicitly closed. Not even a reference to the underlying reader is kept after it has been closed, so any allocated in-memory buffers can be freed even if the client application still keeps a reference to the proxy reader.

Author:
Maarten Kroon

Constructor Summary
AutoCloseReader(java.io.Reader reader)
          Creates an automatically closing proxy for the given reader.
AutoCloseReader(java.io.Reader reader, DataSourceIf source)
          Creates an automatically closing proxy for the given reader.
 
Method Summary
 void close()
          Closes the underlying reader and replaces the reference to it with a ClosedReader instance.
 
Methods inherited from class org.apache.commons.io.input.ProxyReader
mark, markSupported, read, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoCloseReader

public AutoCloseReader(java.io.Reader reader)
Creates an automatically closing proxy for the given reader.

Parameters:
in - underlying reader

AutoCloseReader

public AutoCloseReader(java.io.Reader reader,
                       DataSourceIf source)
Creates an automatically closing proxy for the given reader. When the source is closed, the afterStreamClosed() method of source is called.

Parameters:
in - underlying reader
Method Detail

close

public void close()
           throws java.io.IOException
Closes the underlying reader and replaces the reference to it with a ClosedReader instance.

This method is automatically called by the read methods when the end of input has been reached.

Note that it is safe to call this method any number of times. The original underlying input stream is closed and discarded only once when this method is first called.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class org.apache.commons.io.input.ProxyReader
Throws:
java.io.IOException - if the underlying input stream can not be closed