1 package org.antlr.works.utils; 2 3 import java.io.BufferedReader ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.InputStreamReader ; 7 import java.util.ArrayList ; 8 import java.util.List ; 9 39 40 public class StreamWatcher extends Thread { 41 42 protected InputStream is; 43 protected String type; 44 protected StreamWatcherDelegate delegate; 45 protected List <String > lines; 46 47 public StreamWatcher(InputStream is, String type, StreamWatcherDelegate delegate) { 48 this.is = is; 49 this.type = type; 50 this.delegate = delegate; 51 lines = new ArrayList <String >(); 52 } 53 54 public List <String > getLines() { 55 return lines; 56 } 57 58 public void run() { 59 try { 60 if(delegate != null) 61 delegate.streamWatcherDidStarted(); 62 63 BufferedReader br = new BufferedReader (new InputStreamReader (is)); 64 String line; 65 while ( (line = br.readLine()) != null) { 66 lines.add(line); 67 if(delegate != null) 68 delegate.streamWatcherDidReceiveString(line+"\n"); 69 } 70 } catch (IOException e) { 71 if(delegate != null) 72 delegate.streamWatcherException(e); 73 else 74 e.printStackTrace(); 75 } 76 } 77 } 78 | Popular Tags |