Package jexer.net
Class TelnetInputStream
- java.lang.Object
-
- java.io.InputStream
-
- jexer.net.TelnetInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,SessionInfo
public class TelnetInputStream extends java.io.InputStream implements SessionInfo
TelnetInputStream works with TelnetSocket to perform the telnet protocol.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.void
close()
Closes this input stream and releases any system resources associated with the stream.int
getIdleTime()
Get the time this session was idle.java.lang.String
getLanguage()
Language getter.TelnetSocket
getSocket()
Get the socket associated with this input steram.long
getStartTime()
Get the time this session was started.java.lang.String
getTerminalType()
Get the terminal type as reported by the telnet Terminal Type option.java.lang.String
getUsername()
Username getter.int
getWindowHeight()
Text window height getter.int
getWindowWidth()
Text window width getter.void
mark(int readLimit)
Marks the current position in this input stream.boolean
markSupported()
Tests if this input stream supports the mark and reset methods.void
queryWindowSize()
Re-query the text window size.int
read()
Reads the next byte of data from the input stream.int
read(byte[] b)
Reads some number of bytes from the input stream and stores them into the buffer array b.int
read(byte[] b, int off, int len)
Reads up to len bytes of data from the input stream into an array of bytes.void
reset()
Repositions this stream to the position at the time the mark method was last called on this input stream.void
setIdleTime(int seconds)
Set the time this session was idle.void
setLanguage(java.lang.String language)
Language setter.void
setUsername(java.lang.String username)
Username setter.long
skip(long n)
Skips over and discards n bytes of data from this input stream.
-
-
-
Method Detail
-
getStartTime
public long getStartTime()
Get the time this session was started.- Specified by:
getStartTime
in interfaceSessionInfo
- Returns:
- the number of millis since midnight, January 1, 1970 UTC
-
getIdleTime
public int getIdleTime()
Get the time this session was idle.- Specified by:
getIdleTime
in interfaceSessionInfo
- Returns:
- the number of seconds since the last user input event from this session
-
setIdleTime
public void setIdleTime(int seconds)
Set the time this session was idle.- Specified by:
setIdleTime
in interfaceSessionInfo
- Parameters:
seconds
- the number of seconds since the last user input event from this session
-
getUsername
public java.lang.String getUsername()
Username getter.- Specified by:
getUsername
in interfaceSessionInfo
- Returns:
- the username
-
setUsername
public void setUsername(java.lang.String username)
Username setter.- Specified by:
setUsername
in interfaceSessionInfo
- Parameters:
username
- the value
-
getLanguage
public java.lang.String getLanguage()
Language getter.- Specified by:
getLanguage
in interfaceSessionInfo
- Returns:
- the language
-
setLanguage
public void setLanguage(java.lang.String language)
Language setter.- Specified by:
setLanguage
in interfaceSessionInfo
- Parameters:
language
- the value
-
getTerminalType
public java.lang.String getTerminalType()
Get the terminal type as reported by the telnet Terminal Type option.- Returns:
- the terminal type
-
getWindowWidth
public int getWindowWidth()
Text window width getter.- Specified by:
getWindowWidth
in interfaceSessionInfo
- Returns:
- the window width
-
getWindowHeight
public int getWindowHeight()
Text window height getter.- Specified by:
getWindowHeight
in interfaceSessionInfo
- Returns:
- the window height
-
queryWindowSize
public void queryWindowSize()
Re-query the text window size.- Specified by:
queryWindowSize
in interfaceSessionInfo
-
available
public int available() throws java.io.IOException
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.- Overrides:
available
in classjava.io.InputStream
- Returns:
- an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream.
- Throws:
java.io.IOException
- if an I/O error occurs
-
close
public void close() throws java.io.IOException
Closes this input stream and releases any system resources associated with the stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- if an I/O error occurs
-
mark
public void mark(int readLimit)
Marks the current position in this input stream.- Overrides:
mark
in classjava.io.InputStream
- Parameters:
readLimit
- the maximum limit of bytes that can be read before the mark position becomes invalid
-
markSupported
public boolean markSupported()
Tests if this input stream supports the mark and reset methods.- Overrides:
markSupported
in classjava.io.InputStream
- Returns:
- true if this stream instance supports the mark and reset methods; false otherwise
-
read
public int read() throws java.io.IOException
Reads the next byte of data from the input stream.- Specified by:
read
in classjava.io.InputStream
- Returns:
- the next byte of data, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
java.io.IOException
- if an I/O error occurs
-
read
public int read(byte[] b) throws java.io.IOException
Reads some number of bytes from the input stream and stores them into the buffer array b.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
java.io.IOException
- if an I/O error occurs
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the buffer into which the data is read.off
- the start offset in array b at which the data is written.len
- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
java.io.IOException
- if an I/O error occurs
-
reset
public void reset() throws java.io.IOException
Repositions this stream to the position at the time the mark method was last called on this input stream. This is not supported by TelnetInputStream, so IOException is always thrown.- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
- if this function is used
-
skip
public long skip(long n) throws java.io.IOException
Skips over and discards n bytes of data from this input stream.- Overrides:
skip
in classjava.io.InputStream
- Parameters:
n
- the number of bytes to be skipped- Returns:
- the actual number of bytes skipped
- Throws:
java.io.IOException
- if an I/O error occurs
-
getSocket
public TelnetSocket getSocket()
Get the socket associated with this input steram.- Returns:
- the socket
-
-