From 7ff6373d0caf26db10cad6b4bc6fb2f1d324df59 Mon Sep 17 00:00:00 2001
From: zzz <zzz@i2pmail.org>
Date: Tue, 20 Jul 2021 10:31:52 -0400
Subject: [PATCH] Output stream to string optimizations

---
 .../i2p/router/web/helpers/OldConsoleHelper.java  | 15 +++++++--------
 .../src/src/i2p/susi/webmail/WebMail.java         |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/OldConsoleHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/OldConsoleHelper.java
index 17ba10c918..66055a1708 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/OldConsoleHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/OldConsoleHelper.java
@@ -1,8 +1,7 @@
 package net.i2p.router.web.helpers;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Date;
 
@@ -28,9 +27,9 @@ public class OldConsoleHelper extends HelperBase {
                 renderStatusHTML(_out);
                 return "";
             } else {
-                ByteArrayOutputStream baos = new ByteArrayOutputStream(2*1024);
-                renderStatusHTML(new OutputStreamWriter(baos));
-                return baos.toString();
+                StringWriter sw = new StringWriter(2*1024);
+                renderStatusHTML(sw);
+                return sw.toString();
             }
         } catch (IOException ioe) {
             return "<b>Error displaying the console.</b>";
@@ -44,9 +43,9 @@ public class OldConsoleHelper extends HelperBase {
                 gen.generateStatsPage(_out, _full);
                 return "";
             } else {
-                ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024);
-                gen.generateStatsPage(new OutputStreamWriter(baos), _full);
-                return baos.toString();
+                StringWriter sw = new StringWriter(32*1024);
+                gen.generateStatsPage(sw, _full);
+                return sw.toString();
             }
         } catch (IOException ioe) {
             return "<b>Error displaying the console.</b>";
diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java
index 0b7bf55e85..2436429f9b 100644
--- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java
+++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java
@@ -2828,7 +2828,7 @@ public class WebMail extends HttpServlet
 			try {
 				ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
 				draft.getPart().outputRaw(baos);
-				body.append(new String(baos.toByteArray(), "ISO-8859-1"));
+				body.append(baos.toString("ISO-8859-1"));
 			} catch (IOException ioe) {
 				ok = false;
 				sessionObject.error += ioe.getMessage() + '\n';
-- 
GitLab