1 17 18 19 20 package org.apache.fop.visual; 21 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.Reader ; 26 27 31 public class StreamRedirector implements Runnable { 32 33 private InputStream in; 34 private RedirectorLineHandler handler; 35 private Exception exception; 36 37 41 public StreamRedirector(InputStream in, RedirectorLineHandler handler) { 42 this.in = in; 43 this.handler = handler; 44 } 45 46 49 public boolean hasFailed() { 50 return (this.exception != null); 51 } 52 53 56 public Exception getException() { 57 return this.exception; 58 } 59 60 61 public void run() { 62 this.exception = null; 63 try { 64 Reader inr = new java.io.InputStreamReader (in); 65 BufferedReader br = new BufferedReader (inr); 66 if (handler != null) { 67 handler.notifyStart(); 68 } 69 String line = null; 70 while ((line = br.readLine()) != null) { 71 if (handler != null) { 72 handler.handleLine(line); 73 } 74 } 75 if (handler != null) { 76 handler.notifyStart(); 77 } 78 } catch (IOException ioe) { 79 this.exception = ioe; 80 } 81 } 82 } | Popular Tags |