Adjust the default capability to reduce memory allocation

This commit is contained in:
Glavo
2021-11-27 03:31:38 +08:00
committed by Yuhui Huang
parent 32fad77104
commit 10dbcf63b7
2 changed files with 5 additions and 3 deletions

View File

@@ -17,6 +17,8 @@
*/ */
package org.jackhuang.hmcl.util; package org.jackhuang.hmcl.util;
import org.jackhuang.hmcl.util.io.IOUtils;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@@ -34,7 +36,7 @@ public final class Logging {
} }
public static final Logger LOG = Logger.getLogger("HMCL"); public static final Logger LOG = Logger.getLogger("HMCL");
private static ByteArrayOutputStream storedLogs = new ByteArrayOutputStream(); private static final ByteArrayOutputStream storedLogs = new ByteArrayOutputStream(IOUtils.DEFAULT_BUFFER_SIZE);
public static void start(Path logFolder) { public static void start(Path logFolder) {
LOG.setLevel(Level.ALL); LOG.setLevel(Level.ALL);
@@ -100,7 +102,7 @@ public final class Logging {
new Date(record.getMillis()), new Date(record.getMillis()),
record.getSourceClassName(), record.getSourceMethodName(), record.getLevel().getName(), record.getSourceClassName(), record.getSourceMethodName(), record.getLevel().getName(),
record.getMessage() record.getMessage()
}); }, new StringBuffer(128), null).toString();
if (record.getThrown() != null) if (record.getThrown() != null)
log += StringUtils.getStackTrace(record.getThrown()); log += StringUtils.getStackTrace(record.getThrown());

View File

@@ -37,7 +37,7 @@ public final class StringUtils {
} }
public static String getStackTrace(Throwable throwable) { public static String getStackTrace(Throwable throwable) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
try { try {
throwable.printStackTrace(new PrintStream(stream, false, "UTF-8")); throwable.printStackTrace(new PrintStream(stream, false, "UTF-8"));
return stream.toString("UTF-8"); return stream.toString("UTF-8");