From cefe159ce09bb3f63d083bc7e34cabb53a1aa4d6 Mon Sep 17 00:00:00 2001 From: Pratik Shelarkar Date: Sun, 3 Dec 2023 01:41:58 +0530 Subject: [PATCH] removed System.out --- .../app/desktop/util/TextAreaPrintStream.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/TextAreaPrintStream.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/TextAreaPrintStream.java index df73131722b..304d8d02a09 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/TextAreaPrintStream.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/TextAreaPrintStream.java @@ -17,6 +17,8 @@ package org.apache.lucene.luke.app.desktop.util; +import java.io.IOException; +import java.io.OutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; import javax.swing.JTextArea; @@ -24,20 +26,32 @@ import javax.swing.JTextArea; /** PrintStream for text areas */ public final class TextAreaPrintStream extends PrintStream { - private final JTextArea textArea; + private final JTextArea textArea; - public TextAreaPrintStream(JTextArea textArea) { - super(System.out, false, StandardCharsets.UTF_8); - this.textArea = textArea; - } + public TextAreaPrintStream(JTextArea textArea) { + super(new OutputStream() { + @Override + public void write(int b) throws IOException { + textArea.append(String.valueOf((char) b)); + } - @Override - public void flush() { - textArea.append(toString()); - clear(); - } - - public void clear() { - textArea.setText(""); - } + @Override + public void write(byte[] b, int off, int len) throws IOException { + String s = new String(b, off, len, StandardCharsets.UTF_8); + textArea.append(s); + } + }, false, StandardCharsets.UTF_8); + + this.textArea = textArea; + } + + @Override + public void flush() { + textArea.repaint(); // Optional: Repaint the text area after appending text + clear(); + } + + public void clear() { + textArea.setText(""); + } }