Package org.python.util
Class ConsoleInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.python.util.ConsoleInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public abstract class ConsoleInputStream extends java.io.FilterInputStreamThis class is intended to replaceSystem.infor 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 ofgetLine().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
iomodule orfilebuilt-in, that should deal with encoding.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConsoleInputStream.EOLPolicyEnumeration used to specify whether an end-of-line should be added or replaced at the end of each line read.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()The number of bytes left unread in the current encoded line.voidmark(int readlimit)Mark is not supported.booleanmarkSupported()Mark is not supported.intread()Read the next byte of data from the buffered input line.intread(byte[] b, int off, int len)Reads up to len bytes of data from this input stream into an array of bytes.voidreset()Mark is not supported.longskip(long n)Skip forward n bytes within the current encoded line.
-
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionRead 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.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException, java.io.EOFExceptionReads 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 callsgetLine()at most once to get a line of characters from the console, and encodes them as bytes to be read back from the stream.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOExceptionjava.io.EOFException
-
skip
public long skip(long n) throws java.io.IOExceptionSkip forward n bytes within the current encoded line. A call toskipwill not result in reading a new line withgetLine().- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOExceptionThe number of bytes left unread in the current encoded line.- Overrides:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
mark
public void mark(int readlimit)
Mark is not supported.- Overrides:
markin classjava.io.FilterInputStream
-
reset
public void reset() throws java.io.IOExceptionMark is not supported.- Overrides:
resetin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
Mark is not supported.- Overrides:
markSupportedin classjava.io.FilterInputStream
-
-