Package org.marketcetera.util.file
Class WriterWrapper
- java.lang.Object
-
- org.marketcetera.util.file.WriterWrapper
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class WriterWrapper extends Object implements Closeable
A wrapped writer. It may wrap a regular file, the standard output or error stream, or any otherWriterinstance. This wrapper is intended to wrapWriterinstances 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: WriterWrapper.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description private booleanmSkipCloseprivate WritermWriter
-
Constructor Summary
Constructors Constructor Description WriterWrapper(File file)Creates a new wrapped writer that wraps the given regular file.WriterWrapper(File file, SignatureCharset requestedSignatureCharset)Creates a new wrapped writer that wraps the given regular file.WriterWrapper(Writer writer)Creates a new wrapped writer that wraps the given writer.WriterWrapper(Writer writer, boolean skipClose)Creates a new wrapped writer that wraps the given writer.WriterWrapper(String name)Creates a new wrapped writer that wraps: the regular file with the given name (data is appended to the file if the name is prefixed bySpecialNames.PREFIX_APPEND), or the standard output stream (if the name isSpecialNames.STANDARD_OUTPUT), or the standard error stream (if the name isSpecialNames.STANDARD_ERROR). The default JVM charset is used to convert characters into bytes.WriterWrapper(String name, SignatureCharset requestedSignatureCharset)Creates a new wrapped writer that wraps: the regular file with the given name (data is appended to the file if the name is prefixed bySpecialNames.PREFIX_APPEND), or the standard output stream (if the name isSpecialNames.STANDARD_OUTPUT), or the standard error stream (if the name isSpecialNames.STANDARD_ERROR). A writer that can inject unicode BOMs is used as a proxy; that writer uses the given signature/charset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleangetSkipClose()Returns true if the receiver's underlying writer will not be closed whenclose()is called.WritergetWriter()Returns the receiver's underlying writer.
-
-
-
Field Detail
-
mWriter
private Writer mWriter
-
mSkipClose
private boolean mSkipClose
-
-
Constructor Detail
-
WriterWrapper
public WriterWrapper(String name, SignatureCharset requestedSignatureCharset) throws FileNotFoundException
Creates a new wrapped writer that wraps:- the regular file with the given name (data is appended to the
file if the name is prefixed by
SpecialNames.PREFIX_APPEND), or - the standard output stream (if the name is
SpecialNames.STANDARD_OUTPUT), or - the standard error stream (if the name is
SpecialNames.STANDARD_ERROR).
- Parameters:
name- The file name.requestedSignatureCharset- The signature/charset. 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 writing.
- the regular file with the given name (data is appended to the
file if the name is prefixed by
-
WriterWrapper
public WriterWrapper(String name) throws FileNotFoundException
Creates a new wrapped writer that wraps:- the regular file with the given name (data is appended to the
file if the name is prefixed by
SpecialNames.PREFIX_APPEND), or - the standard output stream (if the name is
SpecialNames.STANDARD_OUTPUT), or - the standard error stream (if the name is
SpecialNames.STANDARD_ERROR).
- Parameters:
name- The file name.- Throws:
FileNotFoundException- Thrown if the name represents a regular file, and it cannot be opened for writing.
- the regular file with the given name (data is appended to the
file if the name is prefixed by
-
WriterWrapper
public WriterWrapper(File file, SignatureCharset requestedSignatureCharset) throws FileNotFoundException
Creates a new wrapped writer that wraps the given regular file. A writer that can inject unicode BOMs is used as a proxy; that writer uses the given signature/charset.- Parameters:
file- The file.requestedSignatureCharset- The signature/charset. It may be null to use the default JVM charset.- Throws:
FileNotFoundException- Thrown if the file cannot be opened for writing.
-
WriterWrapper
public WriterWrapper(File file) throws FileNotFoundException
Creates a new wrapped writer that wraps the given regular file. The default JVM charset is used to convert characters into bytes.- Parameters:
file- The file.- Throws:
FileNotFoundException- Thrown if the file cannot be opened for writing.
-
WriterWrapper
public WriterWrapper(Writer writer, boolean skipClose)
Creates a new wrapped writer that wraps the given writer. The writer may or may not be closed whenclose()is called depending on the given flag.- Parameters:
writer- The writer.skipClose- True if the underlying writer should not be closed.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getWriter
public Writer getWriter()
Returns the receiver's underlying writer.- Returns:
- The writer.
-
getSkipClose
public boolean getSkipClose()
Returns true if the receiver's underlying writer will not be closed whenclose()is called.- Returns:
- True if so.
-
-