public abstract class ConsoleInputStream
extends java.io.FilterInputStream
System.in
for use with console libraries that
provide a line-oriented input mechanism. The console libraries provide a method to get the next
line from the console as a String. Particular sub-classes should wrap this character-oriented
method in a definition of getLine()
.
The libraries JLine and Java Readline have both been used to give Jython line-recall, editing and
a line history preserved between sessions. Both deal with the console encoding internally, and
interact with the user in terms of a buffer of characters. Our need in Jython is to access a
byte-stream encoding the characters, with line-endings, since it is the text layer of the Python
io stack, whether we are using the io
module or file
built-in, that
should deal with encoding.
Modifier and Type | Class and Description |
---|---|
static class |
ConsoleInputStream.EOLPolicy
Enumeration used to specify whether an end-of-line should be added or replaced at the end of
each line read.
|
Modifier and Type | Field and Description |
---|---|
protected static java.nio.ByteBuffer |
EMPTY_BUF
Empty buffer
|
protected java.nio.charset.Charset |
encoding
The character encoding specified in the constructor.
|
protected java.lang.String |
eol
The end-of-line String specified in the constructor.
|
protected ConsoleInputStream.EOLPolicy |
eolPolicy
The
ConsoleInputStream.EOLPolicy specified in the constructor. |
protected static java.lang.String |
LINE_SEPARATOR
Platform-defined end-of-line for convenience
|
Modifier and Type | Method and Description |
---|---|
int |
available()
The number of bytes left unread in the current encoded line.
|
protected abstract java.lang.CharSequence |
getLine()
Get one line of input from the console.
|
void |
mark(int readlimit)
Mark is not supported.
|
boolean |
markSupported()
Mark is not supported.
|
int |
read()
Read the next byte of data from the buffered input line.
|
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this input stream into an array of bytes.
|
void |
reset()
Mark is not supported.
|
long |
skip(long n)
Skip forward n bytes within the current encoded line.
|
protected final ConsoleInputStream.EOLPolicy eolPolicy
ConsoleInputStream.EOLPolicy
specified in the constructor.protected final java.lang.String eol
protected final java.nio.charset.Charset encoding
protected static final java.nio.ByteBuffer EMPTY_BUF
protected static final java.lang.String LINE_SEPARATOR
protected abstract java.lang.CharSequence getLine() throws java.io.IOException, java.io.EOFException
java.io.IOException
- in case of an errorjava.io.EOFException
- if the library recognises an end-of-file conditionpublic int read() throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException, java.io.EOFException
getLine()
at most once to get a line of
characters from the console, and encodes them as bytes to be read
back from the stream.read
in class java.io.FilterInputStream
java.io.IOException
java.io.EOFException
public long skip(long n) throws java.io.IOException
skip
will not
result in reading a new line with getLine()
.skip
in class java.io.FilterInputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.FilterInputStream
java.io.IOException
public void mark(int readlimit)
mark
in class java.io.FilterInputStream
public void reset() throws java.io.IOException
reset
in class java.io.FilterInputStream
java.io.IOException
public boolean markSupported()
markSupported
in class java.io.FilterInputStream