Bug 205803 - CommandLauncher / ConsoleOutputStream combination doesn't handle characters well
Summary: CommandLauncher / ConsoleOutputStream combination doesn't handle characters well
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-09 07:22 EDT by Kevin Bracey CLA
Modified: 2020-09-04 15:27 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 Kevin Bracey CLA 2007-10-09 07:22:36 EDT
Build ID: M20070921-1145

Steps To Reproduce:
Use CommandLauncher and ConsoleOutputStream to read textual input from a tool that is producing something other than ASCII/Latin-1.


More information:
I'm assuming CommandLauncher and ConsoleOutputStream are intended as API, even though I've found no documentation.

They are certainly handy for calling an external tool; takes a lot of tedium out of the work.

However, the combination rather oddly goes from bytes to chars (in InputStreamReader) to bytes (in ProcessClosure) to chars (in ConsoleOutputStream). And in the final step, ConsoleOutputStream is not designed to handle anything other than ASCII.

Either ConsoleOutputStream should be improved have a more intelligent byte->char conversion, or a new API using chars should be given. Such as:

CommandLauncher.waitAndRead(Writer out, Writer err);

this can then be used with CharArrayWriter to achieve the same functionality.

As far as I can see ConsoleOutputStream as it stands could be reduced in its entirety to:

public class ConsoleOutputStream extends ByteArrayOutputStream {
	public synchronized String readBuffer() {
		return toString();
	}
}

which should then give appropriate encoding behaviour.
Comment 1 Kevin Bracey CLA 2007-10-11 16:17:19 EDT
Oops, that suggested implementation should be:

public class ConsoleOutputStream extends ByteArrayOutputStream {
	public synchronized String readBuffer() {
	    String result = toString();
	    reset();
		return result;
	}
}