public class

ConsoleReaderOutputStream

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

Class Overview

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
synchronized void flush()
ConsoleReader getConsoleReader()
Get the ConsoleReader instance that we're using internally
void setAsyncMode()
Set asynchronous mode.
void setSyncMode()
Set synchronous mode.
synchronized 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.
synchronized void write(int b)
[Expand]
Inherited Methods
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable

Public Constructors

public ConsoleReaderOutputStream (ConsoleReader reader)

Public Methods

public synchronized void flush ()

public ConsoleReader getConsoleReader ()

Get the ConsoleReader instance that we're using internally

public 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.

public 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)

public synchronized 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.

Throws
IOException

public synchronized void write (int b)

Throws
IOException