You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2019/04/07 12:30:47 UTC

[lucene-solr] 07/34: Simplify the TextAreaPrintStream and remove unused params (it's a hack anyways): TODO: Change CheckIndex and Optimize to use Appendable instead of PrintStream

This is an automated email from the ASF dual-hosted git repository.

uschindler pushed a commit to branch jira/lucene-2562-luke-swing-3
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 85be0a429cb0a0e888b742b8b9611e54c2f00ff3
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Fri Apr 5 12:58:19 2019 +0200

    Simplify the TextAreaPrintStream and remove unused params (it's a hack anyways): TODO: Change CheckIndex and Optimize to use Appendable instead of PrintStream
---
 .../dialog/menubar/CheckIndexDialogFactory.java    |  4 +--
 .../dialog/menubar/OptimizeIndexDialogFactory.java |  2 +-
 .../luke/app/desktop/util/TextAreaPrintStream.java | 31 ++++++----------------
 3 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/CheckIndexDialogFactory.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/CheckIndexDialogFactory.java
index c98faa1..e19d32d 100644
--- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/CheckIndexDialogFactory.java
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/CheckIndexDialogFactory.java
@@ -275,7 +275,7 @@ public final class CheckIndexDialogFactory implements DialogOpener.DialogFactory
           indicatorLbl.setVisible(true);
           TextAreaPrintStream ps;
           try {
-            ps = new TextAreaPrintStream(logArea, new ByteArrayOutputStream(), StandardCharsets.UTF_8, log);
+            ps = new TextAreaPrintStream(logArea);
             CheckIndex.Status status = toolsModel.checkIndex(ps);
             ps.flush();
             return status;
@@ -355,7 +355,7 @@ public final class CheckIndexDialogFactory implements DialogOpener.DialogFactory
           logArea.setText("");
           TextAreaPrintStream ps;
           try {
-            ps = new TextAreaPrintStream(logArea, new ByteArrayOutputStream(), StandardCharsets.UTF_8, log);
+            ps = new TextAreaPrintStream(logArea);
             toolsModel.repairIndex(status, ps);
             statusLbl.setText("Done");
             ps.flush();
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/OptimizeIndexDialogFactory.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/OptimizeIndexDialogFactory.java
index 508e20c..447b10c 100644
--- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/OptimizeIndexDialogFactory.java
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/OptimizeIndexDialogFactory.java
@@ -220,7 +220,7 @@ public final class OptimizeIndexDialogFactory implements DialogOpener.DialogFact
           indicatorLbl.setVisible(true);
           TextAreaPrintStream ps;
           try {
-            ps = new TextAreaPrintStream(logArea, new ByteArrayOutputStream(), StandardCharsets.UTF_8, log);
+            ps = new TextAreaPrintStream(logArea);
             toolsModel.optimize(expungeCB.isSelected(), (int) maxSegSpnr.getValue(), ps);
             ps.flush();
           } catch (UnsupportedEncodingException e) {
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 3f8464c..790c1be 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
@@ -19,10 +19,8 @@ package org.apache.lucene.luke.app.desktop.util;
 
 import javax.swing.JTextArea;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
 import org.slf4j.Logger;
@@ -30,36 +28,23 @@ import org.slf4j.Logger;
 /** PrintStream for text areas */
 public final class TextAreaPrintStream extends PrintStream {
 
-  private Logger log;
+  private final ByteArrayOutputStream baos;
 
-  private ByteArrayOutputStream baos;
+  private final JTextArea textArea;
 
-  private JTextArea textArea;
-
-  public TextAreaPrintStream(JTextArea textArea, ByteArrayOutputStream baos, Charset charset, Logger log) throws UnsupportedEncodingException {
-    super(baos, false, charset.name());
-    this.baos = baos;
+  public TextAreaPrintStream(JTextArea textArea) throws UnsupportedEncodingException {
+    super(new ByteArrayOutputStream(), false, StandardCharsets.UTF_8.name()); // TODO: replace by Charset in Java 11
+    this.baos = (ByteArrayOutputStream) out;
     this.textArea = textArea;
-    this.log = log;
     baos.reset();
   }
 
   @Override
-  public void println(String s) {
-    try {
-      baos.write(s.getBytes(StandardCharsets.UTF_8));
-      baos.write('\n');
-    } catch (IOException e) {
-      log.error(e.getMessage(), e);
-    }
-  }
-
-  @Override
   public void flush() {
     try {
-      textArea.append(baos.toString(StandardCharsets.UTF_8.name()));
-    } catch (IOException e) {
-      log.error(e.getMessage(), e);
+      textArea.append(baos.toString(StandardCharsets.UTF_8.name())); // TODO: replace by Charset in Java 11
+    } catch (UnsupportedEncodingException e) {
+      setError();
     } finally {
       baos.reset();
     }