Bug 183901 - [api][terminal] Make the remote-to-terminal communication use an OutputStream
Summary: [api][terminal] Make the remote-to-terminal communication use an OutputStream
Status: CLOSED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: Terminal (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 2.0   Edit
Assignee: Michael Scharf CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks: 165893
  Show dependency tree
 
Reported: 2007-04-24 22:57 EDT by Michael Scharf CLA
Modified: 2008-08-13 13:18 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Scharf CLA 2007-04-24 22:57:53 EDT
There are two streams of data:
1. terminal-to-remote (e.g. characters entered into the terminal by the user)
2. remote-to-terminal (e.g. text to be displayed in the terminal)

For historic reasons terminal-to-remote (1) is an OutputStream but
remote-to-terminal uses ITerminalControl.writeToTerminal(String data).
This is a very ugly asymmetry. writeToTerminal has additional problems, 
because the communication is bytes (8 bit) but the String is chars (16 bit).
If the method is not used carefully (e.g. new String(bytes) is used), the 
platform's default charset determines how the bytes are converted into chars.

To fix this: remote-to-terminal should also be an OutputStream!
Comment 1 Michael Scharf CLA 2007-05-04 19:34:55 EDT
Added ITerminalControl.getRemoteToTerminalOutputStream() that return an OutputStream for connections to write to the terminal.

I created a new class called TerminalInputStream which is essentially an implementation of PipedOutputStream/PipedIntputStream that actually works efficiently. PipedOutputStream/PipedIntputStream is extremely slow (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4404700). For the terminal it was about 1kb/sec (depending of the buffer-size used). My implementation can handle megabytes/sec.

TerminalInputStream also starts a Runnable in the Display thread, each time data is written to the OutputStream. The runnable should read data from the TerminalInputStream until no more data is available. The availability of data is time-limited: when the time running the runnable exceeds a certain amount of time, the TerminalInputStream returns 0 on available() and the runnable is rescheduled again.

TerminalText now uses a InputStreamReader decorating the TerminalInputStream using an "ISO-8859-1" encoding. Maybe the encoding should be done more flexible...
Comment 2 Martin Oberhuber CLA 2007-05-07 08:39:05 EDT
(In reply to comment #1)
> PipedOutputStream/PipedIntputStream is extremely slow (see
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4404700).

FYI, the SSH library used by Eclipse (com.jcraft.jsch) also uses PipedInputStrea, with a 32KB buffer:

   PipedInputStream pis = new PipedInputStream(os, 32*1024)

If your implementation is a lot more efficient, it might make sense contributing it to JSch for the next release?
Comment 3 Martin Oberhuber CLA 2007-05-18 20:32:41 EDT
Closing.
Comment 4 Martin Oberhuber CLA 2008-08-13 13:18:41 EDT
[target cleanup] 2.0 M7 was the original target milestone for this bug