Skip to content

Commit

Permalink
[FIXED JENKINS-11874] if can't obtain computer's charset, use UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Dec 12, 2011
1 parent 9bc221b commit 9cfe7a9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/com/deluan/jenkins/plugins/rtc/JazzClient.java
Expand Up @@ -13,6 +13,7 @@
import org.kohsuke.stapler.framework.io.WriterOutputStream;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -170,7 +171,7 @@ private ByteArrayOutputStream popen(ArgumentListBuilder args)
// scm produces text in the platform default encoding, so we need to convert it back to UTF-8
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WriterOutputStream o = new WriterOutputStream(new OutputStreamWriter(baos, "UTF-8"),
Computer.currentComputer().getDefaultCharset());
getDefaultCharset());

PrintStream output = listener.getLogger();
ForkOutputStream fos = new ForkOutputStream(o, output);
Expand All @@ -182,4 +183,13 @@ private ByteArrayOutputStream popen(ArgumentListBuilder args)
throw new AbortException();
}
}

private Charset getDefaultCharset() {
// First check if we can get currentComputer. See issue JENKINS-11874
if (Computer.currentComputer() != null) {
return Computer.currentComputer().getDefaultCharset();
} else {
return Charset.forName("UTF-8");
}
}
}

0 comments on commit 9cfe7a9

Please sign in to comment.