public class ConsoleOutputStream
extends java.io.FilterOutputStream
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.| Constructor and Description |
|---|
ConsoleOutputStream(java.io.OutputStream out,
int promptCapacity)
Create a wrapper on an
OutputStream that holds a copy of the last incomplete
line written to it (as bytes), in case it is needed as a console prompt. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
void |
write(int b)
This write method steals a copy of each byte in a buffer while passing it on to the wrapped
stream.
|
public ConsoleOutputStream(java.io.OutputStream out,
int promptCapacity)
OutputStream that holds a copy of the last incomplete
line written to it (as bytes), in case it is needed as a console prompt.out - the stream wrapped (normally System.out)promptCapacity - maximum number of bytes to bufferpublic void write(int b)
throws java.io.IOException
getPrompt(Charset).write in class java.io.FilterOutputStreamjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.FilterOutputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterOutputStreamjava.io.IOException