: Class SystemPrintStream

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

## com.dalsemi.shell.server
Class SystemPrintStream

    java.lang.Object
      |
      +--java.io.OutputStream
            |
            +--java.io.FilterOutputStream
                  |
                  +--java.io.PrintStream
                        |
                        +--com.dalsemi.shell.server.SystemPrintStream

public class SystemPrintStream
extends PrintStream

A basic implementation of a PrintStream for use as `System.out` and `System.err`. This class allows its root stream to be set, and overrides all of its parent's (PrintStream) methods. This allows special cases to be handled at the expense of some code space. For instance, a `SystemPrintStream` can be set to protect itself if an `IOException` occurs. This is useful, for example, from a telnet session if you run a Java program in the background. The program and the session are both using a socket for output to the user. If the user exits the telnet session, that socket goes away, and the process would receive a `SocketException` on every write, probably killing the process. If it is set to protect itself, the `SystemPrintStream` will set its internal root stream to a `NullOutputStream` when it detects an `IOException`. Thus, the process can continue to run.

See Also:
  `SystemInputStream`, `NullOutputStream`, `Session`

Field Summary
`boolean` | `append` If this `SystemPrintStream` outputs to a file, this variable determines if the output will be appended to the file or if it will over-write the file.
`String` | `fileOutName` The name of the file this `SystemPrintStream` is outputting to, or null if this stream is not redirecting to a file.
`protected Session` | `session` The user session that owns this `SystemPrintStream`.
`boolean` | `shieldsUp` Allows the `SystemPrintStream` to protect itself.

Fields inherited from class java.io.FilterOutputStream
`out`

Constructor Summary
`SystemPrintStream(OutputStream root)` Creates a new `SystemPrintStream` with the specified underlying root `OutputStream`.
`SystemPrintStream(OutputStream out, boolean autoFlush)` Creates a new `SystemPrintStream` with the specified underlying root `OutputStream`.
`SystemPrintStream(OutputStream root, String fileOutName, boolean append)` Creates a new `SystemPrintStream` with the specified underlying root `OutputStream`.

Method Summary
`OutputStream` | `getRootOutputStream()` Returns the underlying root `OutputStream` of this stream.
`void` | `print(boolean b)` Prints the value of the `boolean` argument.
`void` | `print(char c)` Prints the value of the `char` argument according to the default encoding scheme.
`void` | `print(char[] s)` Prints the `char` array according to the default encoding scheme.
`void` | `print(double d)` Prints the double precision floating point argument by calling the `Double.toString(double)` method.
`void` | `print(float f)` Prints the floating point argument by calling the `Float.toString(float)` method.
`void` | `print(int i)` Prints the `int` argument by calling the `Integer.toString(int)` method.
`void` | `print(long l)` Prints the `long` argument by calling the `Long.toString(long)` method.
`void` | `print(Object obj)` Prints a `String` representation of the argument `Object` by invoking its `toString()` method, or prints the `String` "null" if the argument is `null`.
`void` | `print(String s)` Prints the `String` argument to the underlying root stream, or the `String` "null" if the argument is `null`.
`void` | `println()` Writes the end of line sequence CRLF to the underlying `OutputStream`.
`void` | `println(boolean x)` Prints the value of the `boolean` argument, followed by the end of line sequence.
`void` | `println(char x)` Prints the value of the `char` argument according to the default encoding scheme, followed by the end of line sequence.
`void` | `println(char[] x)` Prints the character array according to the default encoding scheme, followed by the end of line sequence.
`void` | `println(double x)` Prints the double precision floating point argument by calling the `Double.toString(double)` method, followed by the end of line sequence.
`void` | `println(float x)` Prints the floating point argument by calling the `Float.toString(float)` method, followed by the end of line sequence.
`void` | `println(int x)` Prints the `int` argument by calling the `Integer.toString(int)` method, followed by the end of line sequence.
`void` | `println(long x)` Prints the `long` argument by calling the `Long.toString(long)` method, followed by the end of line sequence.
`void` | `println(Object x)` Prints a `String` representation of the argument `Object` by invoking its `toString()` method, or prints the `String` "null" if the argument is `null`, followed by the end of line sequence.
`void` | `println(String x)` Prints the `String` argument to the underlying root stream, or the `String` "null" if the argument is `null`, followed by the end of line sequence.
`void` | `setRootStream(OutputStream root)` Sets the underlying root output stream of this stream.
`void` | `setSession(Session s)` Informs this stream of its owning session.
`void` | `write(byte[] buf, int off, int len)` Writes a portion of a `byte` array to the underlying `OutputStream`.
`void` | `write(int b)` Writes the byte to the underlying `OutputStream`.

Methods inherited from class java.io.PrintStream
`checkError, close, flush, setError`

Methods inherited from class java.io.FilterOutputStream
`write`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### session

    protected Session session

  The user session that owns this `SystemPrintStream`. This could be a session on the serial port, through a telnet or FTP connection, or through any other user created `Session`.

### fileOutName

    public String fileOutName

  The name of the file this `SystemPrintStream` is outputting to, or null if this stream is not redirecting to a file.

### append

    public boolean append

  If this `SystemPrintStream` outputs to a file, this variable determines if the output will be appended to the file or if it will over-write the file.

### shieldsUp

    public boolean shieldsUp

  Allows the `SystemPrintStream` to protect itself. When a process is run in the background and not redirected to a file, then its `OutputStream` is in danger of causing problems if the underlying `Session` is terminated. If the `Session` ends and the `shieldsUp` variable is true, this `SystemPrintStream`'s internal root stream must be reassigned to a `NullOutputStream`.

Constructor Detail

### SystemPrintStream

    public SystemPrintStream(OutputStream root)

  Creates a new `SystemPrintStream` with the specified underlying root `OutputStream`.
  Parameters:
    `root` - the internal root `OutputStream` for this `SystemPrintStream`

### SystemPrintStream

    public SystemPrintStream(OutputStream out,
                             boolean autoFlush)

  Creates a new `SystemPrintStream` with the specified underlying root `OutputStream`.
  Parameters:
    `root` - the internal root `OutputStream` for this `SystemPrintStream`
    `autoFlush` - set to true if the `SystemPrintStream` should flush the internal root stream on every write call

### SystemPrintStream

    public SystemPrintStream(OutputStream root,
                             String fileOutName,
                             boolean append)

  Creates a new `SystemPrintStream` with the specified underlying root `OutputStream`. In this case, the underlying root stream should be for a file.
  Parameters:
    `root` - the internal root `OutputStream` for this `SystemPrintStream`
    `fileOutName` - name of the file this `SystemPrintStream` is directing its output towards
    `append` - true if this `SystemPrintStream` should append to the file, false if it should over-write the file

Method Detail

### setRootStream

    public void setRootStream(OutputStream root)

  Sets the underlying root output stream of this stream.
  Parameters:
    `root` - the new underlying stream to use
  See Also:
    `getRootOutputStream()`

### getRootOutputStream

    public OutputStream getRootOutputStream()

  Returns the underlying root `OutputStream` of this stream.
  Returns:
    the underlying root stream
  See Also:
    `setRootStream(java.io.OutputStream)`

### setSession

    public void setSession(Session s)

  Informs this stream of its owning session. This allows this stream to call into the session when needed.
  Parameters:
    `session` - the owning session

### write

    public void write(int b)

  Writes the byte to the underlying `OutputStream`.
  Overrides:
    write in class PrintStream
  Parameters:
    `b` - value to be written

### write

    public void write(byte[] buf,
                      int off,
                      int len)

  Writes a portion of a `byte` array to the underlying `OutputStream`.
  Overrides:
    write in class PrintStream
  Parameters:
    `buf` - a `byte` array
    `off` - offset in the `byte` array to begin writing bytes from
    `len` - number of bytes to write

### print

    public void print(boolean b)

  Prints the value of the `boolean` argument. If the argument is `true`, the `String` "true" is printed. If the argument is `false`, the `String` "false" is printed.
  Overrides:
    print in class PrintStream
  Parameters:
    `b` - the `boolean` value to print
  See Also:
    `println(boolean)`

### print

    public void print(char c)

  Prints the value of the `char` argument according to the default encoding scheme.
  Overrides:
    print in class PrintStream
  Parameters:
    `c` - the `char` to be printed
  See Also:
    `println(char)`

### print

    public void print(int i)

  Prints the `int` argument by calling the `Integer.toString(int)` method.
  Overrides:
    print in class PrintStream
  Parameters:
    `i` - the `int` to be printed
  See Also:
    `println(int)`

### print

    public void print(long l)

  Prints the `long` argument by calling the `Long.toString(long)` method.
  Overrides:
    print in class PrintStream
  Parameters:
    `l` - the `long` to be printed
  See Also:
    `println(long)`

### print

    public void print(float f)

  Prints the floating point argument by calling the `Float.toString(float)` method.
  Overrides:
    print in class PrintStream
  Parameters:
    `f` - the `float` to be printed
  See Also:
    `println(float)`

### print

    public void print(double d)

  Prints the double precision floating point argument by calling the `Double.toString(double)` method.
  Overrides:
    print in class PrintStream
  Parameters:
    `d` - the `double` to be printed
  See Also:
    `println(double)`

### print

    public void print(char[] s)

  Prints the `char` array according to the default encoding scheme.
  Overrides:
    print in class PrintStream
  Parameters:
    `s` - the `char` array to be printed
  See Also:
    `println(char[])`

### print

    public void print(String s)

  Prints the `String` argument to the underlying root stream, or the `String` "null" if the argument is `null`.
  Overrides:
    print in class PrintStream
  Parameters:
    `s` - the `String` to print
  See Also:
    `println(java.lang.String)`

### print

    public void print(Object obj)

  Prints a `String` representation of the argument `Object` by invoking its `toString()` method, or prints the `String` "null" if the argument is `null`.
  Overrides:
    print in class PrintStream
  Parameters:
    `obj` - the `Object` to print
  See Also:
    `println(java.lang.Object)`

### println

    public void println()

  Writes the end of line sequence CRLF to the underlying `OutputStream`.
  Overrides:
    println in class PrintStream

### println

    public void println(boolean x)

  Prints the value of the `boolean` argument, followed by the end of line sequence. If the argument is `true`, the `String` "true" is printed. If the argument is `false`, the `String` "false" is printed.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `boolean` value to print
  See Also:
    `print(boolean)`

### println

    public void println(char x)

  Prints the value of the `char` argument according to the default encoding scheme, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `char` to be printed
  See Also:
    `print(char)`

### println

    public void println(int x)

  Prints the `int` argument by calling the `Integer.toString(int)` method, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `int` to be printed
  See Also:
    `print(int)`

### println

    public void println(long x)

  Prints the `long` argument by calling the `Long.toString(long)` method, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `long` to be printed
  See Also:
    `print(long)`

### println

    public void println(float x)

  Prints the floating point argument by calling the `Float.toString(float)` method, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `float` to be printed
  See Also:
    `print(float)`

### println

    public void println(double x)

  Prints the double precision floating point argument by calling the `Double.toString(double)` method, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `double` to be printed
  See Also:
    `print(double)`

### println

    public void println(char[] x)

  Prints the character array according to the default encoding scheme, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `char` array to be printed
  See Also:
    `print(char[])`

### println

    public void println(String x)

  Prints the `String` argument to the underlying root stream, or the `String` "null" if the argument is `null`, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `String` to print
  See Also:
    `print(java.lang.String)`

### println

    public void println(Object x)

  Prints a `String` representation of the argument `Object` by invoking its `toString()` method, or prints the `String` "null" if the argument is `null`, followed by the end of line sequence.
  Overrides:
    println in class PrintStream
  Parameters:
    `x` - the `Object` to print
  See Also:
    `print(java.lang.Object)`

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