projects
/
cfb.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4f1e35c
)
Command: make reliance on system default encoding for reading streams explicit.
author
Chris Jaekl
<cejaekl@yahoo.com>
Sun, 1 Nov 2015 02:11:46 +0000
(11:11 +0900)
committer
Chris Jaekl
<cejaekl@yahoo.com>
Sun, 1 Nov 2015 02:11:46 +0000
(11:11 +0900)
prod/net/jaekl/cfb/util/Command.java
patch
|
blob
|
history
diff --git
a/prod/net/jaekl/cfb/util/Command.java
b/prod/net/jaekl/cfb/util/Command.java
index 672aac2fec9364a106922d40b14286536a4c3eff..be3b07e534c5c6f04ac7cd13e4d94c9b3ca945dc 100644
(file)
--- a/
prod/net/jaekl/cfb/util/Command.java
+++ b/
prod/net/jaekl/cfb/util/Command.java
@@
-6,8
+6,14
@@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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 class Command {
+ public static final String UTF_8 = "UTF-8";
+ private Charset m_charset;
+
public static class Result
{
private int m_retCode;
public static class Result
{
private int m_retCode;
@@
-25,14
+31,14
@@
public class Command {
public String getStderr() { return m_stderr; }
}
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();
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
}
@Override
@@
-61,7
+67,12
@@
public class Command {
public Command()
{
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
}
public Result exec(String cmd) throws IOException