ConsoleReaderOutputStream

public class ConsoleReaderOutputStream
extends OutputStream

java.lang.Object
   ↳ java.io.OutputStream
     ↳ com.android.tradefed.log.ConsoleReaderOutputStream


An OutputStream that can be used to make System.out.print() play nice with the user's ConsoleReader buffer.

In trivial performance tests, this class did not have a measurable performance impact.

Summary

Public constructors

ConsoleReaderOutputStream(ConsoleReader reader)

Public methods

void flush()

ConsoleReader getConsoleReader()

Get the ConsoleReader instance that we're using internally

void setAsyncMode()

Set asynchronous mode.

void setSyncMode()

Set synchronous mode.

void write(byte[] b, int off, int len)

A special implementation to keep the user's command buffer visible when asynchronous tasks write to stdout.

void write(int b)

Public constructors

ConsoleReaderOutputStream

ConsoleReaderOutputStream (ConsoleReader reader)

Parameters
reader ConsoleReader

Public methods

flush

void flush ()

getConsoleReader

ConsoleReader getConsoleReader ()

Get the ConsoleReader instance that we're using internally

Returns
ConsoleReader

setAsyncMode

void setAsyncMode ()

Set asynchronous mode. This occurs immediately after we display the command prompt and begin waiting for user input. In this mode, the most recent line on the screen is guaranteed to be the command prompt. In particular, asynchronous tasks may attempt to print to the screen, and we will shuffle the prompt when they do so.

setSyncMode

void setSyncMode ()

Set synchronous mode. This occurs after the user has taken some action, such that the most recent line on the screen is guaranteed to _not_ be the command prompt. In this case, we disable the prompt-shuffling behavior (which requires that the most recent line on the screen be the prompt)

write

void write (byte[] b, 
                int off, 
                int len)

A special implementation to keep the user's command buffer visible when asynchronous tasks write to stdout.

If a full-line write is detected (one that terminates with "\n"), we:

  1. Clear the current line (which will contain the prompt and the user's buffer
  2. Print the full line(s), which will drop us on a new line
  3. Redraw the prompt and the user's buffer

By doing so, we never skip any asynchronously-logged output, but we still keep the prompt and the user's buffer as the last items on the screen.

FIXME: We should probably buffer output and only write full lines to the console.

Parameters
b byte
off int
len int
Throws
IOException

write

void write (int b)

Parameters
b int
Throws
IOException