1 19 package org.netbeans.modules.ruby.rubyproject.execution; 20 21 import java.io.BufferedReader ; 22 import java.io.BufferedWriter ; 23 import java.io.OutputStream ; 24 import java.io.OutputStreamWriter ; 25 import java.io.OutputStreamWriter ; 26 import java.io.Reader ; 27 import java.lang.InterruptedException ; 28 import java.util.List ; 29 30 import org.openide.util.Exceptions; 31 32 33 47 class InputForwarder implements Runnable { 48 private OutputStream out; 49 private Reader reader; 50 private FileLocator fileLocator; 51 private List <OutputRecognizer> recognizers; 52 private boolean cancelled; 53 54 public InputForwarder(OutputStream outstream, Reader in) { 55 out = outstream; 56 reader = in; 57 this.fileLocator = fileLocator; 58 this.recognizers = recognizers; 59 } 60 61 public void cancel() { 62 synchronized (this) { 63 cancelled = true; 64 } 65 } 66 67 public void run() { 68 BufferedReader input = null; 69 BufferedWriter output = null; 70 71 try { 72 input = new BufferedReader (reader); 73 output = new BufferedWriter (new OutputStreamWriter (out)); 74 75 char[] buffer = new char[512]; 76 77 while (true) { 78 if (Thread.interrupted()) { 79 return; 80 } 81 82 synchronized (this) { 83 if (cancelled) { 84 return; 85 } 86 } 87 88 try { 94 Thread.sleep(300); 95 } catch (InterruptedException ie) { 96 return; 97 } 98 99 int lenRead; 100 101 while ((input.ready()) && ((lenRead = input.read(buffer, 0, buffer.length)) > 0)) { 102 output.write(buffer, 0, lenRead); 103 output.flush(); 104 } 105 } 106 } catch (Exception ioe) { 107 Exceptions.printStackTrace(ioe); 108 } finally { 109 try { 110 if (input != null) { 111 input.close(); 112 } 113 114 if (output != null) { 115 output.close(); 116 } 117 } catch (Exception ioe) { 118 Exceptions.printStackTrace(ioe); 119 } 120 } 121 } 122 } 123 | Popular Tags |