|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.io.InputStream
|
+--com.dalsemi.shell.server.SystemInputStream
This is an implementation of an InputStream for use as System.in.
Since the underlying root InputStream for a TINI program can come from
a serial port, a socket, or any other kind of input, the differing behaviors of these
input devices must be reconciled by this class. This class must ensure that input
becomes available only after an end of line sequence is received, and that the amount
available does not represent any 'inaccessible' data (if the data has not been followed
by an end of line character). It must also handle '\r', '\n', and '\r\n' as end of
line sequences.
SystemPrintStream,
Session| Field Summary | |
protected byte[] |
buffer
The internal buffer that holds all the data that has been received and not yet read by an application. |
protected boolean |
ECHO
Indicates whether or not to echo the character just read. |
protected int |
endPos
The ending position in the internal buffer where valid data ends. |
protected static byte[] |
ERASE
Byte sequence for a backspace. |
String |
fileInName
If this SystemInputStream reads from a file,
this represents the name of the file. |
protected PrintStream |
out
The 'echo' stream. |
protected boolean |
rawMode
Indicates that the SystemInputStream should return
data as soon as it is available, and not wait until an
end of line sequence is received. |
protected InputStream |
root
The underlying InputStream that this
reads from. |
protected Session |
session
The user session that owns this SystemInputStream. |
protected int |
startPos
The starting position in the internal buffer where valid data is located. |
| Constructor Summary | |
SystemInputStream(InputStream in,
PrintStream out)
Creates a new SystemPrintStream with the
specified underlying root stream and echo stream. |
|
SystemInputStream(InputStream in,
PrintStream out,
String fileInName)
Creates a new SystemInputStream with the
specified underlying root stream and echo stream. |
|
| Method Summary | |
int |
available()
Returns the number of bytes that can be read from this input stream without blocking. |
boolean |
errorOccurred()
|
InputStream |
getRootStream()
Returns the underlying root InputStream of this stream. |
protected void |
increaseBuffer(int newDataSize)
Ensures the internal buffer is large enough for more data. |
protected int |
rawAvailable()
This method should be overridden by subclassing InputStreams. |
protected int |
rawRead()
This method should be overridden by subclassing InputStreams. |
protected int |
rawRead(byte[] buff,
int off,
int len)
Reads from the underlying stream and returns data even if an end of line sequence is not received. |
int |
read()
Reads the next character from the stream. |
int |
read(byte[] buff,
int off,
int len)
Tries to read len bytes from the stream. |
String |
readLine()
Reads a line of text up to but not including the end of line sequence. |
void |
setEcho(boolean echo)
Turns on and off echoing back characters read by this stream. |
void |
setEchoStream(PrintStream echo)
Sets the PrintStream to echo back characters read by this stream. |
void |
setRawMode(boolean rawMode)
Sets the mode for reading data from the underlying stream. |
void |
setRootStream(InputStream newIn)
Sets the underlying InputStream to use. |
void |
setSession(Session session)
Informs this stream of its owning session. |
| Methods inherited from class java.io.InputStream |
close,
mark,
markSupported,
read,
reset,
skip |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected Session session
SystemInputStream.protected InputStream root
InputStream that this
reads from.protected PrintStream out
ECHO is true,
this PrintStream will write everything it reads. This is useful
in a telnet session, for instance, when a user types something and
it needs to be echoed back to the telnet client.ECHOprotected boolean rawMode
SystemInputStream should return
data as soon as it is available, and not wait until an
end of line sequence is received.rawRead(),
rawRead(byte[],int,int)protected byte[] buffer
protected int startPos
protected int endPos
public String fileInName
SystemInputStream reads from a file,
this represents the name of the file.protected boolean ECHO
outprotected static final byte[] ERASE
| Constructor Detail |
public SystemInputStream(InputStream in,
PrintStream out)
SystemPrintStream with the
specified underlying root stream and echo stream.in - underlying InputStream to useout - stream for echo characters
public SystemInputStream(InputStream in,
PrintStream out,
String fileInName)
SystemInputStream with the
specified underlying root stream and echo stream. Calling
this constructor signifies that the underlying
InputStream is reading from a file.in - underlying InputStream to useout - stream for echo charactersfileInName - name of the file this stream is reading from| Method Detail |
public void setEcho(boolean echo)
echo - true to enable echoing, false
to disable itsetEchoStream(java.io.PrintStream)public void setEchoStream(PrintStream echo)
PrintStream to echo back characters read by this stream.
Note: you must call setEcho(true) to enable echoing.echo - stream to echo back characters readsetEcho(boolean)public void setSession(Session session)
session - the owning session
protected int rawRead()
throws IOException
InputStreams.
It should only be called from within a synchronized block. It blocks until
data is available and returns the first value it reads. It does not wait
for an end of line sequence.rawRead(byte[],int,int),
rawAvailable(),
setRawMode(boolean)
protected int rawRead(byte[] buff,
int off,
int len)
throws IOException
Reads from the underlying stream and returns data even if an end of line sequence is not received. If not operating in raw reading mode, it also checks and handles backspace events. Stops if it finds an end of stream.
This method should only be called from within a synchronized block.
rawRead(),
setRawMode(boolean),
rawAvailable()
protected int rawAvailable()
throws IOException
InputStreams.
It returns the amount available from the underlying root stream.
This is not the amount available if the SystemInputStream
is not in raw mode.setRawMode(boolean),
rawRead(),
rawRead(byte[],int,int)public String readLine()
String of length 0).
InputStream, or null if no more input will be
available due to the end of the streamread(),
read(byte[],int,int)
public final int read()
throws IOException
-1 if the end of the stream has been
reachedsetRawMode(boolean),
readLine(),
read(byte[],int,int)
public int read(byte[] buff,
int off,
int len)
throws IOException
len bytes from the stream.
If the end of stream is encountered, no more data
will be read. If raw mode is not enabled, only
data that has been followed by an end of line
sequence or the end of the stream will be reported.
This method will block until enough data is available
to return or the end of the stream is reached.buff - byte array to store the data readoff - offset to begin storing data in the arraylen - amount of data requested-1 if the end of the stream has been
reachedread(),
readLine(),
setRawMode(boolean)protected void increaseBuffer(int newDataSize)
synchronized block.newDataSize - the amount of new data
that is about to be copied into the buffer
at location endPos
public final int available()
throws IOException
setRawMode(boolean)public void setRawMode(boolean rawMode)
true, any call to read data will
return the next available data from the underlying stream.
If raw mode is false, read calls only report data
that has been followed by an end of line character, or the
end of the stream, even if the read must block to do so.rawMode - false to block for an end of line
sequence, true to return any available datarawRead(),
rawRead(byte[],int,int),
rawAvailable(),
read(),
read(byte[],int,int),
available()public void setRootStream(InputStream newIn)
InputStream to use.newIn - new root InputStream to usegetRootStream()public InputStream getRootStream()
InputStream of this stream.setRootStream(java.io.InputStream)public boolean errorOccurred()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||