1 22 package org.columba.mail.spellcheck.cswilly; 23 24 import java.io.BufferedReader ; 25 import java.io.BufferedWriter ; 26 import java.io.IOException ; 27 import java.io.InputStreamReader ; 28 import java.io.OutputStreamWriter ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 33 38 public class AspellEngine implements Engine { 39 BufferedReader _aSpellReader; 40 BufferedWriter _aSpellWriter; 41 String _aSpellWelcomeMsg; 42 Process _aSpellProcess; 43 44 public AspellEngine(String aSpellCommandLine) throws SpellException { 45 try { 46 Runtime runtime = Runtime.getRuntime(); 47 _aSpellProcess = runtime.exec(aSpellCommandLine); 48 49 _aSpellReader = new BufferedReader (new InputStreamReader ( 50 _aSpellProcess.getInputStream())); 51 52 _aSpellWriter = new BufferedWriter (new OutputStreamWriter ( 53 _aSpellProcess.getOutputStream())); 54 55 _aSpellWelcomeMsg = _aSpellReader.readLine(); 56 } catch (IOException e) { 57 String msg = "Cannot create aspell process."; 58 throw new SpellException(msg, e); 59 } 60 } 61 62 72 public List checkLine(String line) throws SpellException { 73 try { 74 List results = new ArrayList (); 75 76 final String spellCheckLinePrefix = "^"; 77 _aSpellWriter.write(spellCheckLinePrefix + line); 78 _aSpellWriter.newLine(); 79 _aSpellWriter.flush(); 80 81 String response = _aSpellReader.readLine(); 82 83 while ((response != null) && !response.equals("")) { 84 Result result = new Result(response); 85 results.add(result); 86 87 response = _aSpellReader.readLine(); 88 } 89 90 return results; 91 } catch (IOException e) { 92 String msg = "Cannot access aspell process."; 93 throw new SpellException(msg, e); 94 } 95 } 96 97 public String getVersion() { 98 return _aSpellWelcomeMsg; 99 } 100 101 public void stop() { 102 _aSpellProcess.destroy(); 103 } 104 } 105 | Popular Tags |