Reputation: 715
I am trying to call linux aspell program for pt_BR spellchecking in Java using Java Runtime.getRuntime().exec(). The issue is that it seems something wroing with input/output char encoding. some input word is splitted into two words at accent letter position, and output is displayed with � for accent letters. I can see aspell can spell-check pt_BR correctly in command pipeline mode. The code for setting up aspell is following:
String[] aspellCommand = new String[4];
aspellCommand[0] = "aspell";
aspellCommand[1] = "-a";
aspellCommand[2] = "--keymapping=ispell";
aspellCommand[3] = "--lang=pt_BR";
String[] envArray = new String[0];
process = Runtime.getRuntime().exec(aspellCommand, envArray);
System.out.println(Charset.defaultCharset()); /utf-8
InputStreamReader ir = new InputStreamReader(process.getInputStream(), "utf-8");
OutputStreamWriter or = new OutputStreamWriter(process.getOutputStream(), "utf-8");
aspellOutputStream = new BufferedReader(ir);
aspellInputStream = new PrintWriter(or,true);
System.out.println(ir.getEncoding()); /utf-8
System.out.println(or.getEncoding()); /utf-8
The code to feed input into aspell:
aspellInputStream.println(misSpelledWord);
The code to read from aspell:
String line = aspellOutputStream.readLine();
I suspect something wrong with IO stream charset encoding, but I don't know where exactly to set them.
Upvotes: 1
Views: 655
Reputation: 715
don't use Runtume.exec which is buggy. use ProcessBuilder instead. or https://github.com/zeroturnaround/zt-exec
Upvotes: 1