import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
public class Command {
+ public static final String UTF_8 = "UTF-8";
+ private Charset m_charset;
+
public static class Result
{
private int m_retCode;
public String getStderr() { return m_stderr; }
}
- private static class StreamGobbler extends Thread {
+ private class StreamGobbler extends Thread {
private StringBuilder m_sb;
private BufferedReader m_br;
public StreamGobbler(InputStream is) {
m_sb = new StringBuilder();
- m_br = new BufferedReader(new InputStreamReader(is));
+ m_br = new BufferedReader(new InputStreamReader(is, m_charset));
}
@Override
public Command()
{
- // no-op
+ try {
+ m_charset = Charset.forName(System.getProperty("file.encoding", UTF_8));
+ }
+ catch (IllegalCharsetNameException | UnsupportedCharsetException exc) {
+ m_charset = Charset.forName(UTF_8);
+ }
}
public Result exec(String cmd) throws IOException