My application has a console where all the system's printstream content is rerouted to.
My application will also output special characters, specifically other languages (asian languages, Russian, Arabic, etc)
I'm using a JTextArea as the console out:
consoleOutput = new JTextArea(1, 50);
DefaultCaret caret = (DefaultCaret) consoleOutput.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
Font font = new Font("Consolas", Font.PLAIN, 12);
consoleOutput.setFont(font);
JScrollPane scrollPane = new JScrollPane(consoleOutput);
this.add(scrollPane, BorderLayout.CENTER);
//CHANGE OUTPUT TO THIS CONSOLE
PrintStream out = new PrintStream(new TextAreaOutput(consoleOutput));
System.setOut(out);
System.setErr(out);
And this class to rerout the printstream:
public class TextAreaOutput extends OutputStream {
JTextArea outputConsole;
public TextAreaOutput(JTextArea outputConsole) {
this.outputConsole = outputConsole;
}
@Override
public void write(int b) throws IOException {
outputConsole.append( String.valueOf( ( char )b ) );
}
}
This works and the printstream prints to this jtextarea. However, I have encoding issues. Special characters like ▒, █, .نت, 览, etc
do not render correctly. Some might be hardcoded into source files (I'm using UTF-8), but some might be extracted from the web with selenium webdriver.