/*
* Copyright (c) 2005 Thomas Weise
*
* E-Mail : tweise@gmx.de
* Creation Date : 2005-06-22 16:25:35
* Original Filename: org.sfc.io.DefaultOutputStream.java
* Version : 1.0.2
* Last modification: 2006-03-07
* by: Thomas Weise
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.sfc.io;
import java.io.IOException;
import java.io.OutputStream;
/**
* This class is a wrapper for OutputStream
s that makes them
* reference counted.
* @author Thomas Weise
*/
final class DefaultOutputStream extends ReferenceCountedOutputStream
{
/**
* The internal output-stream.
*/
private final OutputStream m_os;
/**
* Create a reference counted OutputStream
.
*
* @param p_original The underlying object.
*/
DefaultOutputStream (final OutputStream p_original)
{
super();
this.m_os = p_original;
}
/**
* The internal dispose method.
* @throws IOException If the underlying was closed and caused an
* IOException.
*/
@Override
protected final void dispose () throws IOException
{
try
{
this.m_os.close();
}
finally
{
super.dispose();
}
}
/**
* Writes the specified byte
to this output stream.
*
* The write
method of DefaultOutputStream
* calls the write
method of its underlying output stream,
* that is, it performs out.write(b).
*
* Implements the abstract write method of OutputStream.
*
* @param p_b the byte
.
* @exception IOException if an I/O error occurs.
*/
@Override
public final void write(int p_b) throws IOException
{
this.m_os.write(p_b);
}
/**
* Writes b.length
bytes to this output stream.
*
* The write
method of DefaultOutputStream
* calls its write
method of three arguments with the
* arguments b
, 0
, and
* b.length
.
*
* Note that this method does not call the one-argument
* write
method of its underlying stream with the single
* argument b
.
*
* @param p_b the data to be written.
* @exception IOException if an I/O error occurs.
* @see DefaultOutputStream#write(byte[], int, int)
*/
@Override
public final void write(final byte[] p_b) throws IOException
{
this.m_os.write(p_b);
}
/**
* Writes len
bytes from the specified
* byte
array starting at offset off
to
* this output stream.
*
* The write
method of DefaultOutputStream
* calls the write
method of one argument on each
* byte
to output.
*
* Note that this method does not call the write
method
* of its underlying input stream with the same arguments. Subclasses
* of DefaultOutputStream
should provide a more efficient
* implementation of this method.
*
* @param p_b the data.
* @param p_off the start offset in the data.
* @param p_len the number of bytes to write.
* @exception IOException if an I/O error occurs.
* @see DefaultOutputStream#write(int)
*/
@Override
public final void write(final byte[] p_b,
final int p_off,
final int p_len) throws IOException
{
this.m_os.write(p_b, p_off, p_len);
}
/**
* Flushes this output stream and forces any buffered output bytes
* to be written out to the stream.
*
* The flush
method of DefaultOutputStream
* calls the flush
method of its underlying output stream.
*
* @exception IOException if an I/O error occurs.
*/
@Override
public final void flush() throws IOException
{
this.m_os.flush();
}
}