org.marketcetera.util.file
Class ReaderWrapper

java.lang.Object
  extended by org.marketcetera.util.file.ReaderWrapper
All Implemented Interfaces:
Closeable

public class ReaderWrapper
extends Object
implements Closeable

A wrapped reader. It may wrap a regular file, the standard input stream, or any other Reader instance. This wrapper is intended to wrap Reader instances for use with CloseableRegistry, hence such instances should not be closed directly, that is, without going through the wrapper's close() method.

Since:
0.5.0
Version:
$Id: ReaderWrapper.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Constructor Summary
ReaderWrapper(File file)
          Creates a new wrapped reader that wraps the given regular file.
ReaderWrapper(File file, DecodingStrategy decodingStrategy)
          Creates a new wrapped reader that wraps the given regular file.
ReaderWrapper(Reader reader)
          Creates a new wrapped reader that wraps the given reader.
ReaderWrapper(Reader reader, boolean skipClose)
          Creates a new wrapped reader that wraps the given reader.
ReaderWrapper(String name)
          Creates a new wrapped reader that wraps the regular file with the given name, or the standard input stream (if the name is SpecialNames.STANDARD_INPUT).
ReaderWrapper(String name, DecodingStrategy decodingStrategy)
          Creates a new wrapped reader that wraps the regular file with the given name, or the standard input stream (if the name is SpecialNames.STANDARD_INPUT).
 
Method Summary
 void close()
           
 Reader getReader()
          Returns the receiver's underlying reader.
 boolean getSkipClose()
          Returns true if the receiver's underlying reader will not be closed when close() is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderWrapper

public ReaderWrapper(String name,
                     DecodingStrategy decodingStrategy)
              throws FileNotFoundException
Creates a new wrapped reader that wraps the regular file with the given name, or the standard input stream (if the name is SpecialNames.STANDARD_INPUT). A reader that recognizes unicode BOMs is used as a proxy; that reader uses the given decoding strategy.

Parameters:
name - The file name.
decodingStrategy - The decoding strategy. It may be null to use the default JVM charset.
Throws:
FileNotFoundException - Thrown if the name represents a regular file, and it cannot be opened for reading.

ReaderWrapper

public ReaderWrapper(String name)
              throws FileNotFoundException
Creates a new wrapped reader that wraps the regular file with the given name, or the standard input stream (if the name is SpecialNames.STANDARD_INPUT). The default JVM charset is used to convert bytes into characters.

Parameters:
name - The file name.
Throws:
FileNotFoundException - Thrown if the name represents a regular file, and it cannot be opened for reading.

ReaderWrapper

public ReaderWrapper(File file,
                     DecodingStrategy decodingStrategy)
              throws FileNotFoundException
Creates a new wrapped reader that wraps the given regular file. A reader that recognizes unicode BOMs is used as a proxy; that reader uses the given decoding strategy.

Parameters:
file - The file.
decodingStrategy - The decoding strategy. It may be null to use the default JVM charset.
Throws:
FileNotFoundException - Thrown if the file cannot be opened for reading.

ReaderWrapper

public ReaderWrapper(File file)
              throws FileNotFoundException
Creates a new wrapped reader that wraps the given regular file. The default JVM charset is used to convert bytes into characters.

Parameters:
file - The file.
Throws:
FileNotFoundException - Thrown if the file cannot be opened for reading.

ReaderWrapper

public ReaderWrapper(Reader reader,
                     boolean skipClose)
Creates a new wrapped reader that wraps the given reader. The reader may or may not be closed when close() is called depending on the given flag.

Parameters:
reader - The reader.
skipClose - True if the underlying reader should not be closed.

ReaderWrapper

public ReaderWrapper(Reader reader)
Creates a new wrapped reader that wraps the given reader. The underlying reader will be closed when close() is called; hence the given reader should not wrap the standard input stream.

Parameters:
reader - The reader.
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

getReader

public Reader getReader()
Returns the receiver's underlying reader.

Returns:
The reader.

getSkipClose

public boolean getSkipClose()
Returns true if the receiver's underlying reader will not be closed when close() is called.

Returns:
True if so.


Copyright © 2012. All Rights Reserved.