mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-10 04:16:02 -04:00
Use StringWriter instead of ByteArrayOutputStream
This commit is contained in:
parent
10dbcf63b7
commit
55092326a4
@ -19,9 +19,7 @@ package org.jackhuang.hmcl.util;
|
|||||||
|
|
||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.charset.CharsetEncoder;
|
import java.nio.charset.CharsetEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -37,13 +35,11 @@ public final class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getStackTrace(Throwable throwable) {
|
public static String getStackTrace(Throwable throwable) {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
|
StringWriter stringWriter = new StringWriter(512);
|
||||||
try {
|
try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
|
||||||
throwable.printStackTrace(new PrintStream(stream, false, "UTF-8"));
|
throwable.printStackTrace(printWriter);
|
||||||
return stream.toString("UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new InternalError(e);
|
|
||||||
}
|
}
|
||||||
|
return stringWriter.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStackTrace(StackTraceElement[] elements) {
|
public static String getStackTrace(StackTraceElement[] elements) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user