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 to as default stream.
 
Constructor Summary
SafeOutputStream(OutputStream ostream)
          Creates a new SafeOutputstream
 
Method Summary
 void close()
          Closes this SafeOutputStream by closing the OutputStream this stream was constructed of.
 boolean doesNothing()
          Indicates whether the instance is doing something or not.
protected  void finalize()
          This method does not close the internal stream.
 void flush()
           
 OutputStream getOutputStream()
          Returns the internal used OutputStream.
 void write(int b)
           
 void write(String s)
          Writes the String.
 void writeln()
          Writes a linebreak.
 void writeln(String s)
          Writes the String and a linebreak.
 
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 to as default stream.

Constructor Detail

SafeOutputStream

public SafeOutputStream(OutputStream ostream)
Creates a new SafeOutputstream

Parameters:
ostream - the internal used OutputStream
Method Detail

close

public void close()
           throws IOException
Closes this SafeOutputStream by closing the OutputStream this stream was constructed of. If this SaveOutputStream 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

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 linebreak.

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

writeln

public void writeln(String s)
             throws IOException
Writes the String and a linebreak.

Parameters:
s - the String
Throws:
IOException - if something is wrong.
See Also:
write(int)

write

public void write(String s)
           throws IOException
Writes the String.

Parameters:
s - the String
Throws:
IOException - if something is 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
This method does not close the internal stream.

Overrides:
finalize in class Object
Throws:
IOException