Package org.marketcetera.util.file
Class OutputStreamWrapper
- java.lang.Object
-
- org.marketcetera.util.file.OutputStreamWrapper
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class OutputStreamWrapper extends Object implements Closeable
A wrapped output stream. It may wrap a regular file, the standard output or error stream, or any otherOutputStreaminstance. This wrapper is intended to wrapOutputStreaminstances 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: OutputStreamWrapper.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description private booleanmSkipCloseprivate OutputStreammStream
-
Constructor Summary
Constructors Constructor Description OutputStreamWrapper(File file)Creates a new wrapped stream that wraps the given regular file.OutputStreamWrapper(OutputStream stream)Creates a new wrapped stream that wraps the given stream.OutputStreamWrapper(OutputStream stream, boolean skipClose)Creates a new wrapped stream that wraps the given stream.OutputStreamWrapper(String name)Creates a new wrapped stream 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).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleangetSkipClose()Returns true if the receiver's underlying stream will not be closed whenclose()is called.OutputStreamgetStream()Returns the receiver's underlying stream.
-
-
-
Field Detail
-
mStream
private OutputStream mStream
-
mSkipClose
private boolean mSkipClose
-
-
Constructor Detail
-
OutputStreamWrapper
public OutputStreamWrapper(String name) throws FileNotFoundException
Creates a new wrapped stream 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
-
OutputStreamWrapper
public OutputStreamWrapper(File file) throws FileNotFoundException
Creates a new wrapped stream that wraps the given regular file.- Parameters:
file- The file.- Throws:
FileNotFoundException- Thrown if the file cannot be opened for writing.
-
OutputStreamWrapper
public OutputStreamWrapper(OutputStream stream, boolean skipClose)
Creates a new wrapped stream that wraps the given stream. The stream may or may not be closed whenclose()is called depending on the given flag.- Parameters:
stream- The stream.skipClose- True if the underlying stream should not be closed.
-
OutputStreamWrapper
public OutputStreamWrapper(OutputStream stream)
Creates a new wrapped stream that wraps the given stream. The underlying stream will be closed whenclose()is called; hence the given stream should not wrap (or be) the standard output or error stream.- Parameters:
stream- The stream.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getStream
public OutputStream getStream()
Returns the receiver's underlying stream.- Returns:
- The stream.
-
getSkipClose
public boolean getSkipClose()
Returns true if the receiver's underlying stream will not be closed whenclose()is called.- Returns:
- True if so.
-
-