System.out so that the console handling
library (JLine or Java Readline) can treat an incomplete line (one without a newline) as a prompt
string, and so know the true position of the cursor. It achieves this by keeping a copy of bytes
that pass through from from upstream to the true System.out, until either a newline
arrives, or a defined capacity (typically the console width) is reached. If client code requests
the partial line as a prompt, that action also empties the buffer. In that case, the client
(which is the console object) is responsible for making the prompt emerge on the real console.
| Modifier and Type | Field and Description |
|---|---|
| protected ByteBuffer | buf
The storage buffer for accumulating the partial line |
| Access | Constructor and Description |
|---|---|
| public | ConsoleOutputStream(OutputStream
the stream wrapped (normally out, int System.out)maximum number of bytes to buffer promptCapacity)Create a wrapper on an |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. Closes this output stream and releases any system resources associated with the stream. |
| public void | flush()
Overrides java. Implements java. Flushes this output stream and forces any buffered output bytes to be written out to the stream. |
| protected CharSequence | |
| public void | write(int
the b)byte.Overrides java. This write method steals a copy of each byte in a buffer while passing it on to the wrapped stream. |
| buf | back to summary |
|---|---|
| protected ByteBuffer buf The storage buffer for accumulating the partial line | |
| ConsoleOutputStream | back to summary |
|---|---|
| public ConsoleOutputStream(OutputStream out, int promptCapacity) Create a wrapper on an
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources associated with the stream.
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Doc from java. Flushes this output stream and forces any buffered output bytes to be written out to the stream.
| |
| getPrompt | back to summary |
|---|---|
| protected CharSequence getPrompt(Charset encoding) Return the stored bytes encoded as characters. Whatever is in the buffer at the point this method is called will be returned, decoded as a CharSequence (from which a String can easily be got) and the buffer left empty. The expectation is that the characters will be issued by the caller as a prompt.
| |
| write | back to summary |
|---|---|
| public void write(int b) throws IOException Overrides java. This write method steals a copy of each byte in a buffer while passing it on to the wrapped
stream. The buffer is reset by each newline, when it overflows, or by the client when it is
taken as a console prompt in
| |