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 |
|---|---|
| public static enum | ConsoleInputStream.
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 |
|---|---|
| private ByteBuffer | buf
Bytes decoded from the last line read. |
| protected static final ByteBuffer | EMPTY_BUF
Empty buffer |
| protected final Charset | encoding
The character encoding specified in the constructor. |
| protected final String | eol
The end-of-line String specified in the constructor. |
| protected final ConsoleInputStream. | |
| protected static final String | LINE_SEPARATOR
Platform-defined end-of-line for convenience |
| Access | Constructor and Description |
|---|---|
| pack-priv | ConsoleInputStream(InputStream
stream to wrap, normally in, Charset System.into use to encode the buffered characters encoding, ConsoleInputStream.choice of how to treat an end-of-line marker eolPolicy,the end-of-line to use when eol)eolPolicy is not LEAVECreate a wrapper configured with end-of-line handling that matches the specific console library being wrapped, and a character encoding matching the expectations of the client. |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. The number of bytes left unread in the current encoded line. |
| private void | fillBuffer()
Get a line of text from the console and re-encode it using the console encoding to bytes that will be returned from this InputStream in subsequent read operations. |
| protected abstract CharSequence | |
| public synchronized void | mark(int
the maximum limit of bytes that can be read before
the mark position becomes invalid. readlimit)Overrides java. Mark is not supported. |
| public boolean | |
| public int | read()
Overrides java. Read the next byte of data from the buffered input line. |
| public int | read(byte[]
the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to len bytes of data from this input stream into an array of bytes. |
| public synchronized void | |
| public long | skip(long
the number of bytes to be skipped. n)Overrides java. Skip forward n bytes within the current encoded line. |
| buf | back to summary |
|---|---|
| private ByteBuffer buf Bytes decoded from the last line read. | |
| EMPTY_BUF | back to summary |
|---|---|
| protected static final ByteBuffer EMPTY_BUF Empty buffer | |
| encoding | back to summary |
|---|---|
| protected final Charset encoding The character encoding specified in the constructor. | |
| eol | back to summary |
|---|---|
| protected final String eol The end-of-line String specified in the constructor. | |
| eolPolicy | back to summary |
|---|---|
| protected final ConsoleInputStream. The | |
| LINE_SEPARATOR | back to summary |
|---|---|
| protected static final String LINE_SEPARATOR Platform-defined end-of-line for convenience | |
| ConsoleInputStream | back to summary |
|---|---|
| pack-priv ConsoleInputStream(InputStream in, Charset encoding, ConsoleInputStream. Create a wrapper configured with end-of-line handling that matches the specific console
library being wrapped, and a character encoding matching the expectations of the client.
Since this is an abstract class, this constructor will be called as the first action of the
library-specific concrete class. The end-of-line policy can be chosen from
| |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. The number of bytes left unread in the current encoded line.
| |
| fillBuffer | back to summary |
|---|---|
| private void fillBuffer() throws IOException, EOFException Get a line of text from the console and re-encode it using the console encoding to bytes that will be returned from this InputStream in subsequent read operations. | |
| getLine | back to summary |
|---|---|
| protected abstract CharSequence getLine() throws IOException, EOFException Get one line of input from the console. Override this method with the actions specific to the library in use.
| |
| mark | back to summary |
|---|---|
| public synchronized void mark(int readlimit) Overrides java. Mark is not supported.
| |
| markSupported | back to summary |
|---|---|
| public boolean markSupported() Overrides java. Mark is not supported.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Read the next byte of data from the buffered input line. The byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been recognised, the value -1 is returned. This method blocks until input data are available, the end of the stream is detected, or an exception is thrown. Normally, an empty line results in an encoded end-of-line being returned.
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException, EOFException Overrides java. Reads up to len bytes of data from this input stream into an array of bytes. If len is not
zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is
returned. This implementation calls
Doc from java. the total number of bytes read into the buffer, or
| |
| reset | back to summary |
|---|---|
| public synchronized void reset() throws IOException Overrides java. Mark is not supported.
| |
| skip | back to summary |
|---|---|
| public long skip(long n) throws IOException Overrides java. Skip forward n bytes within the current encoded line. A call to
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final ConsoleInputStream. | |
| public static final ConsoleInputStream. | |
| public static final ConsoleInputStream. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ConsoleInputStream. | |
| public static ConsoleInputStream. |
| ADD | back to summary |
|---|---|
| public static final ConsoleInputStream. | |
| LEAVE | back to summary |
|---|---|
| public static final ConsoleInputStream. | |
| REPLACE | back to summary |
|---|---|
| public static final ConsoleInputStream. | |
| EOLPolicy | back to summary |
|---|---|
| private EOLPolicy() | |
| valueOf | back to summary |
|---|---|
| public static ConsoleInputStream. | |
| values | back to summary |
|---|---|
| public static ConsoleInputStream. | |