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 java.io.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.
 java.lang.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(java.io.OutputStream root)
          Creates a new SystemPrintStream with the specified underlying root OutputStream.
SystemPrintStream(java.io.OutputStream out, boolean autoFlush)
          Creates a new SystemPrintStream with the specified underlying root OutputStream.
SystemPrintStream(java.io.OutputStream root, java.lang.String fileOutName, boolean append)
          Creates a new SystemPrintStream with the specified underlying root OutputStream.
 
Method Summary
 boolean checkError()
          Flushes the underlying stream and checks to see if an error (IOException) has occurred while communicating with the underlying root stream.
 java.io.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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.
protected  void setError()
          Allows another class to signal that an error has occurred.
 void setRootStream(java.io.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
close, flush
 
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 java.lang.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(java.io.OutputStream root)
Creates a new SystemPrintStream with the specified underlying root OutputStream.
Parameters:
root - the internal root OutputStream for this SystemPrintStream

SystemPrintStream

public SystemPrintStream(java.io.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(java.io.OutputStream root,
                         java.lang.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(java.io.OutputStream root)
Sets the underlying root output stream of this stream.
Parameters:
root - the new underlying stream to use
See Also:
getRootOutputStream()

getRootOutputStream

public java.io.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

checkError

public boolean checkError()
Flushes the underlying stream and checks to see if an error (IOException) has occurred while communicating with the underlying root stream. The error state is not cleared: if an error has occurred, all successive calls to checkError() return true.
Returns:
true if an IOException has occurred
Overrides:
checkError in class java.io.PrintStream

setError

protected void setError()
Allows another class to signal that an error has occurred.
Overrides:
setError in class java.io.PrintStream

write

public void write(int b)
Writes the byte to the underlying OutputStream.
Parameters:
b - value to be written
Overrides:
write in class java.io.PrintStream

write

public void write(byte[] buf,
                  int off,
                  int len)
Writes a portion of a byte array to the underlying OutputStream.
Parameters:
buf - a byte array
off - offset in the byte array to begin writing bytes from
len - number of bytes to write
Overrides:
write in class java.io.PrintStream

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.
Parameters:
b - the boolean value to print
Overrides:
print in class java.io.PrintStream
See Also:
println(boolean)

print

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

print

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

print

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

print

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

print

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

print

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

print

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

print

public void print(java.lang.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.
Parameters:
obj - the Object to print
Overrides:
print in class java.io.PrintStream
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 java.io.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.
Parameters:
x - the boolean value to print
Overrides:
println in class java.io.PrintStream
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.
Parameters:
x - the char to be printed
Overrides:
println in class java.io.PrintStream
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.
Parameters:
x - the int to be printed
Overrides:
println in class java.io.PrintStream
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.
Parameters:
x - the long to be printed
Overrides:
println in class java.io.PrintStream
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.
Parameters:
x - the float to be printed
Overrides:
println in class java.io.PrintStream
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.
Parameters:
x - the double to be printed
Overrides:
println in class java.io.PrintStream
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.
Parameters:
x - the char array to be printed
Overrides:
println in class java.io.PrintStream
See Also:
print(char[])

println

public void println(java.lang.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.
Parameters:
x - the String to print
Overrides:
println in class java.io.PrintStream
See Also:
print(java.lang.String)

println

public void println(java.lang.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.
Parameters:
x - the Object to print
Overrides:
println in class java.io.PrintStream
See Also:
print(java.lang.Object)


Используются технологии uCoz