Package org.marketcetera.util.file
Class ReaderWrapper
- java.lang.Object
-
- org.marketcetera.util.file.ReaderWrapper
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class ReaderWrapper extends Object implements Closeable
A wrapped reader. It may wrap a regular file, the standard input stream, or any otherReaderinstance. This wrapper is intended to wrapReaderinstances for use withCloseableRegistry, hence such instances should not be closed directly, that is, without going through the wrapper'sclose()method.- Since:
- 0.5.0
- Version:
- $Id: ReaderWrapper.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description private ReadermReaderprivate booleanmSkipClose
-
Constructor Summary
Constructors Constructor Description 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 isSpecialNames.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 isSpecialNames.STANDARD_INPUT).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ReadergetReader()Returns the receiver's underlying reader.booleangetSkipClose()Returns true if the receiver's underlying reader will not be closed whenclose()is called.
-
-
-
Field Detail
-
mReader
private Reader mReader
-
mSkipClose
private boolean mSkipClose
-
-
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 isSpecialNames.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 isSpecialNames.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 whenclose()is called depending on the given flag.- Parameters:
reader- The reader.skipClose- True if the underlying reader should not be closed.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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 whenclose()is called.- Returns:
- True if so.
-
-