jcontrol.io
Class Console

java.lang.Object
  extended by jcontrol.io.Console
All Implemented Interfaces:
ConsoleInputStream, ConsoleOutputStream, BasicInputStream, BasicOutputStream

public class Console
extends Object
implements ConsoleOutputStream, ConsoleInputStream

Implements Console communication for JControl.


Field Summary
static ConsoleInputStream in
           
static ConsoleOutputStream out
           
 
Fields inherited from interface jcontrol.comm.ConsoleOutputStream
STD_LF
 
Fields inherited from interface jcontrol.comm.ConsoleInputStream
LF_CHARS
 
Constructor Summary
Console()
          Constructs a default console object.
 
Method Summary
 int available()
          Get the count of bytes that available and can be read once.
 void close()
          Console Outputstreams can't be closed!
 void flush()
          flush buffered bytes
 void mark(int readlimit)
          NOTE: not supported
 boolean markSupported()
          NOTE: not supported
 void print(String text)
          Writes a String to the console.
 void println()
          Writes a linefeed to the console.
 void println(String text)
          Writes a String and a linefeed to the console.
 int read()
          Read exactly 1 byte from the console.
 int read(byte[] b)
          Reads a number of bytes from the console into the overgiven bytearray.
 int read(byte[] b, int off, int len)
          Reads a number of bytes from the console into the overgiven bytearray beginning by offset off and maximum length of len.
 String readLine()
          NOTE: not supported Reads a single String from the console.
 void reset()
          NOTE: not supported
 int skip(int n)
          NOTE: not supported
 void write(byte[] b)
          Writes a Byte-Array to the console.
 void write(byte[] b, int off, int len)
          Writes a Byte-Array beginning by off with length len to the console.
 void write(int b)
          Writes a Byte to to console.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notifyAll, toString, wait
 

Field Detail

out

public static ConsoleOutputStream out

in

public static ConsoleInputStream in
Constructor Detail

Console

public Console()
Constructs a default console object.

Method Detail

print

public void print(String text)
Writes a String to the console. Unicode characters will not be decoded.

Specified by:
print in interface ConsoleOutputStream
Parameters:
text - String to write
See Also:
String

println

public void println(String text)
Writes a String and a linefeed to the console. Unicode characters will not be decoded.

Specified by:
println in interface ConsoleOutputStream
Parameters:
text - String to write
See Also:
String

println

public void println()
Writes a linefeed to the console.

Specified by:
println in interface ConsoleOutputStream

write

public void write(int b)
           throws IOException
Writes a Byte to to console.

Specified by:
write in interface BasicOutputStream
Parameters:
b - byte to write
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

write

public void write(byte[] b)
           throws IOException
Writes a Byte-Array to the console.

Specified by:
write in interface BasicOutputStream
Parameters:
b - bytes to write
Throws:
IOException - if an I/O error occurs.
See Also:
OutputStream.write(byte[], int, int)

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes a Byte-Array beginning by off with length len to the console.

Specified by:
write in interface BasicOutputStream
Parameters:
b - bytes to write
off - start byte offset
len - length of bytes to write
Throws:
IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

readLine

public String readLine()
                throws IOException
NOTE: not supported Reads a single String from the console. The String is received character-by-character until an linefeed character defined in ConsoleInputStream is received. There is a buffer if size BUFFERSIZE allocated to store the received bytes, if the buffer is full a linefeed is forced.

Specified by:
readLine in interface ConsoleInputStream
Returns:
the String read
Throws:
IOException - if an error occurs
See Also:
String

read

public int read()
         throws IOException
Read exactly 1 byte from the console. This method blocks until a byte is available and read.

Specified by:
read in interface BasicInputStream
Returns:
read byte (value between 0..255)
Throws:
IOException - if an I/O error occurs.

read

public int read(byte[] b)
         throws IOException
Reads a number of bytes from the console into the overgiven bytearray. The number of read bytes is returned. If no bytes available, this method doesn't touch the overgiven bytearray and return 0.

Note: this method does the same like read(b, 0, b.length)

Specified by:
read in interface BasicInputStream
Parameters:
b - bytearray to store read bytes
Returns:
the number of read bytes
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.read(byte[], int, int)

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads a number of bytes from the console into the overgiven bytearray beginning by offset off and maximum length of len. The number of read bytes is returned. If no bytes available, this method doesn't touch the overgiven bytearray and return 0.

Specified by:
read in interface BasicInputStream
Parameters:
b - bytearray to store read bytes
off - start offset
len - max length of bytes to read
Returns:
the number of read bytes
Throws:
IOException - if an I/O error occurs.
See Also:
InputStream.read()

flush

public void flush()
           throws IOException
flush buffered bytes

Specified by:
flush in interface BasicOutputStream
Throws:
IOException - if an I/O error occurs.

available

public int available()
              throws IOException
Get the count of bytes that available and can be read once.

Specified by:
available in interface BasicInputStream
Returns:
the number of bytes that can be read from this input stream without blocking.
Throws:
IOException - if an I/O error occurs.

close

public void close()
           throws IOException
Console Outputstreams can't be closed! Throws always an IOException!

Specified by:
close in interface BasicInputStream
Specified by:
close in interface BasicOutputStream
Throws:
IOException - if an I/O error occurs.

mark

public void mark(int readlimit)
NOTE: not supported

Specified by:
mark in interface BasicInputStream
Parameters:
readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.

markSupported

public boolean markSupported()
NOTE: not supported

Specified by:
markSupported in interface BasicInputStream
Returns:
always returning false

reset

public void reset()
           throws IOException
NOTE: not supported

Specified by:
reset in interface BasicInputStream
Throws:
IOException - if this stream has not been makred or if the mark has been invalidated.

skip

public int skip(int n)
         throws IOException
NOTE: not supported

Specified by:
skip in interface BasicInputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.