/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.output; /**
The base class for an OWriter that can wrap around objects like java.io.OutputStreams and java.io.Writer. See OutputStream and Writer.
Source code: OWWrapper.java.
Create a OWWrapper with default settings.
Equal to OWWrapper(false, false, false)
Create a OWWrapper.
Equal to OWWrapper(b_autoFlush, true)
Create a OWWrapper.
Equal to OWWrapper(b_autoFlush, true, b_suppressFinalizeIOX)
Create a OWWrapper.
@param b_autoFlush Should the stream be flushed after every output? Passed directly to setAutoFlush. @param b_closeInFinalize Should the [writer/stream] be closed in finalize? Passed directly to setFlushCloseInFinalize. @param b_suppressFinalizeIOX Should IOExceptions in finalize be suppressed? Passed directly to setSuppressFinalizeIOX. **/ public OWWrapper(boolean b_autoFlush, boolean b_closeInFinalize, boolean b_suppressFinalizeIOX) { setAutoFlush(b_autoFlush); setFlushCloseInFinalize(b_closeInFinalize); setSuppressFinalizeIOX(b_suppressFinalizeIOX); } /**When this class is finalized, should the [writer/stream] be flushed and closed?. See doFlushCloseInFinalize.
@param b_closeInFinalize If true, the [writer/stream] will be closed during finalize. If false, If it will not be closed. **/ public final void setFlushCloseInFinalize(boolean b_closeInFinalize) { bFlushCloseInFinalize = b_closeInFinalize; } /**Should the [writer/stream] be flushed and closed in finalize?. See setFlushCloseInFinalize.
Note that this setting does not affect flushing. No matter what, the stream is flushed, before (potentially) being closed.
@return true If the [writer/stream] will be closed during finalize.Define if flush should be called at the end of every write function.
Get with doSuppressFinalizeIOX
Define if an IOException should be suppressed, should one occur in finalize.
Get with doSuppressFinalizeIOX
Should the [writer/stream] be automatically flushed, after each output?
Set with setAutoFlush
Regardless of this setting, flush is always called in finalize.
@return b_autoFlush exactly as provided to setAutoFlush. If...If an IOException should occur in finalize, should it be suppressed?
Set with setSuppressFinalizeIOX
Write a line of output to the [writer/stream] via println(java.lang.String).
After output is written, if doAutoFlush equals true, call flush.
@param s_message The message to output. @exception AssertException If an IOException is thrown for any reason. **/ public abstract void write(String s_message); /**Write a line of output to the [writer/stream] via print(java.lang.String).
After output is written, if doAutoFlush equals true, call flush.
@param s_message The message to output. @exception AssertException If an IOException is thrown for any reason. **/ public abstract void writeNoln(String s_message); /**Write a newline only, to the [writer/stream] via println().
After output is written, if doAutoFlush equals true, call flush.
@param s_message The message to output. @exception AssertException If an IOException is thrown for any reason. **/ public abstract void newln(); /**Manually flush the [writer/stream] by calling flush().
**/ public abstract void flush(); /**Flush, close and then null the [writer/stream].
flush and close (only if doFlushCloseInFinalize equals true).
Note: The OWWrapper version of this function must be overridden by you--in order to actually flush and close the [writer/stream], and you must call this function (via super.finalize()) in your implementation.
@exception AssertException If doSuppressFinalizeIOX is true and an IOException is thrown for any reason. Note that java.lang.Object.finalize is definitely called, even in the event of an IOException. **/ protected void finalize() throws Throwable { super.finalize(); } }