Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.jstacs.utils
Class SafeOutputStream

    java.lang.Object
      java.io.OutputStream
          de.jstacs.utils.SafeOutputStream

All Implemented Interfaces:
  Closeable, Flushable

    public class SafeOutputStream

extends OutputStream

This class is for any output. For example:

- It enables you to hide the output (use `new SafeOutputStream( null )`).
- It enables you to write the output to the standard output stream (use `new SafeOutputStream( System.out )`).
- It enables you to write the output to a file (use `new SafeOutputStream( new FileOutputStream( ... ) )`).
- ...

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.

Constructor Summary
`SafeOutputStream(OutputStream ostream)` Creates a new `SafeOutputStream`.

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(String s)` Writes a `String`.
`void` | `writeln()` Writes a line break.
`void` | `writeln(String s)` Writes a `String` 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.

Constructor Detail

### SafeOutputStream

    public SafeOutputStream(OutputStream ostream)

  Creates a new `SafeOutputStream`.

  Parameters:
    `ostream` - the internal used `OutputStream`

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(String s)
                 throws IOException

  Writes a `String` and a line break.

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

### write

    public void write(String s)
               throws IOException

  Writes a `String`.

  Parameters:
    `s` - the `String` 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`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD