removed System.out

This commit is contained in:
Pratik Shelarkar 2023-12-03 01:41:58 +05:30
parent 76e976167d
commit cefe159ce0
1 changed files with 28 additions and 14 deletions

View File

@ -17,6 +17,8 @@
package org.apache.lucene.luke.app.desktop.util; package org.apache.lucene.luke.app.desktop.util;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import javax.swing.JTextArea; import javax.swing.JTextArea;
@ -24,20 +26,32 @@ import javax.swing.JTextArea;
/** PrintStream for text areas */ /** PrintStream for text areas */
public final class TextAreaPrintStream extends PrintStream { public final class TextAreaPrintStream extends PrintStream {
private final JTextArea textArea; private final JTextArea textArea;
public TextAreaPrintStream(JTextArea textArea) { public TextAreaPrintStream(JTextArea textArea) {
super(System.out, false, StandardCharsets.UTF_8); super(new OutputStream() {
this.textArea = textArea; @Override
} public void write(int b) throws IOException {
textArea.append(String.valueOf((char) b));
}
@Override @Override
public void flush() { public void write(byte[] b, int off, int len) throws IOException {
textArea.append(toString()); String s = new String(b, off, len, StandardCharsets.UTF_8);
clear(); textArea.append(s);
} }
}, false, StandardCharsets.UTF_8);
public void clear() {
textArea.setText(""); this.textArea = textArea;
} }
@Override
public void flush() {
textArea.repaint(); // Optional: Repaint the text area after appending text
clear();
}
public void clear() {
textArea.setText("");
}
} }