de.jstacs.utils
Class SafeOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by de.jstacs.utils.SafeOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class SafeOutputStream
extends OutputStream

This class is for any output. For example:

The user has to close the stream by hand. It is not closed by the finalize method.

Author:
Jens Keilwagen

Field Summary
static OutputStream DEFAULT_STREAM
          This stream can be used as default stream.
 
Method Summary
 void close()
          Closes the SafeOutputStream by closing the OutputStream this stream was constructed of.
 boolean doesNothing()
          Indicates whether the instance is doing something or not.
protected  void finalize()
           
 void flush()
           
 OutputStream getOutputStream()
          Returns the internal used OutputStream.
static SafeOutputStream getSafeOutputStream(OutputStream out)
          This method returns an instance of SafeOutputStream for a given OutputStream.
 void write(int b)
           
 void write(Object s)
          Writes an Object using Object.toString().
 void writeln()
          Writes a line break.
 void writeln(Object s)
          Writes an Object and a line break.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STREAM

public static final OutputStream DEFAULT_STREAM
This stream can be used as default stream.

Method Detail

getSafeOutputStream

public static SafeOutputStream getSafeOutputStream(OutputStream out)
This method returns an instance of SafeOutputStream for a given OutputStream.

Parameters:
out - the OutputStream
Returns:
an instance of SafeOutputStream for a given OutputStream.

close

public void close()
           throws IOException
Closes the SafeOutputStream by closing the OutputStream this stream was constructed of. If this SafeOutputStream was constructed using System.out this OutputStream will be closed. No outputs via System.out will be possible any more.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException - if something went wrong in closing the output stream

doesNothing

public boolean doesNothing()
Indicates whether the instance is doing something or not.

Returns:
true if the internal OutputStream is null

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

getOutputStream

public OutputStream getOutputStream()
Returns the internal used OutputStream.

Returns:
the internal used OutputStream

writeln

public void writeln()
             throws IOException
Writes a line break.

Throws:
IOException - if something went wrong
See Also:
write(int)

writeln

public void writeln(Object s)
             throws IOException
Writes an Object and a line break.

Parameters:
s - the Object to be written
Throws:
IOException - if something went wrong
See Also:
write(int), Object.toString()

write

public void write(Object s)
           throws IOException
Writes an Object using Object.toString().

Parameters:
s - the Object to be written
Throws:
IOException - if something went wrong
See Also:
write(int)

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

finalize

protected void finalize()
                 throws IOException
Overrides:
finalize in class Object
Throws:
IOException