Top Description Fields Constructors Methods
org.python.util

public Class ConsoleOutputStream

extends FilterOutputStream
Class Inheritance
Imports
java.io.FilterOutputStream, .IOException, .OutputStream, java.nio.ByteBuffer, java.nio.charset.Charset

This class may be used to wrap and replace 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.

Field Summary

Modifier and TypeField and Description
protected ByteBuffer
buf

The storage buffer for accumulating the partial line

Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
ConsoleOutputStream(OutputStream
the stream wrapped (normally System.out)
out
,
int
maximum number of bytes to buffer
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.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with the stream.

public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out to the stream.

protected CharSequence

Returns:

the decoded prompt
getPrompt
(Charset
with which to decode the bytes
encoding
)

Return the stored bytes encoded as characters.

public void
write(int
the byte.
b
)

Overrides java.io.FilterOutputStream.write.

This write method steals a copy of each byte in a buffer while passing it on to the wrapped stream.

Inherited from java.io.FilterOutputStream:
writewrite

Field Detail

bufback to summary
protected ByteBuffer buf

The storage buffer for accumulating the partial line

Constructor Detail

ConsoleOutputStreamback to summary
public ConsoleOutputStream(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.

Parameters
out:OutputStream

the stream wrapped (normally System.out)

promptCapacity:int

maximum number of bytes to buffer

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterOutputStream.close.

Closes this output stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.FilterOutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out to the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getPromptback 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.

Parameters
encoding:Charset

with which to decode the bytes

Returns:CharSequence

the decoded prompt

writeback to summary
public void write(int b) throws IOException

Overrides java.io.FilterOutputStream.write.

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 getPrompt(Charset).

Parameters
b:int

Doc from java.io.FilterOutputStream.write.

the byte.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.write.

if an I/O error occurs.