diff options
author | wjoe <joe@lc8n.com> | 2013-09-20 14:55:48 +0100 |
---|---|---|
committer | wjoe <joe@lc8n.com> | 2013-09-20 14:55:48 +0100 |
commit | e0f1ebdd469cd126c8fee5008207456996bed755 (patch) | |
tree | 65e9bb96cfd2781ae6f8203c128d08613a63842e | |
parent | 47352782cc298e3f63c67f87ab77b882fee47172 (diff) |
Another potential fix for foreign character, with encoding debug
-rwxr-xr-x | blatranslate.java | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/blatranslate.java b/blatranslate.java index 75f8f51..a1b4bbb 100755 --- a/blatranslate.java +++ b/blatranslate.java @@ -26,7 +26,8 @@ import java.io.BufferedReader; import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
-import java.io.PrintStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.io.UnsupportedEncodingException;
public class blatranslate {
@@ -37,8 +38,8 @@ public class blatranslate { String sourceLang = "?";
String targetLang = "";
String sourceString = "";
- PrintStream out = new PrintStream(System.out, true, "UTF-8");
-
+ OutputStreamWriter outStream=new OutputStreamWriter(System.out,"UTF-8");
+ Writer out=outStream;
/* Build query from query or arguments, depending on whether
arguments were given. */
if (args.length == 0) {
@@ -120,21 +121,25 @@ public class blatranslate { if(results.size() > 0){
for(int i=0; i< results.size(); i++){
if (i != 0) {
- out.print(" | ");
+ out.write(" | ");
}
int count = i + 1;
if(langs.size() > i-1 && langs.size() > 0) {
- out.print("Translation ("+langs.get(i)+" to "+targetLang+"): " + results.get(i));
+ out.write("Translation ("+langs.get(i)+" to "+targetLang+"): " + results.get(i));
} else {
- out.print("Translation ("+sourceLang+" to "+targetLang+"): " + results.get(i));
+ out.write("Translation ("+sourceLang+" to "+targetLang+"): " + results.get(i) + " ("+outStream.getEncoding()+")");
}
}
} else {
- out.println("Error: no results.");
+ out.write("Error: no results.\n");
System.exit(1);
+ out.flush();
+ out.close();
}
- System.out.print("\n");
+ out.write("\n");
+ out.flush();
+ out.close();
}
}
|