Output stream to string optimizations

This commit is contained in:
zzz
2021-07-20 10:31:52 -04:00
parent 3bf3a4ff9d
commit 7ff6373d0c
2 changed files with 8 additions and 9 deletions

View File

@@ -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>";

View File

@@ -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';