1 package SnowMailClient.utils; 2 3 4 5 import java.util.*; 6 import java.io.*; 7 8 public class StreamGobbler extends Thread 9 { 10 private InputStream inputStream; 11 private OutputStream outputStream; 12 13 private String streamIdentifier = ""; 14 16 17 18 23 public StreamGobbler( final InputStream inputStream, 24 final OutputStream outputStream ) 25 { 26 this.inputStream = inputStream; 27 this.outputStream = outputStream; 28 } 29 30 31 32 38 public StreamGobbler( final InputStream inputStream, 39 final OutputStream outputStream, 40 final String theStreamIdentifier) 41 { 42 this(inputStream,outputStream); 43 this.streamIdentifier = theStreamIdentifier + "> "; 44 } 45 46 47 48 public void run() 49 { 50 try 51 { 52 PrintWriter printWriter = null; 53 if( this.outputStream != null ) printWriter = new PrintWriter(this.outputStream); 54 final InputStreamReader isr = new InputStreamReader(this.inputStream); 55 final BufferedReader br = new BufferedReader(isr); 56 String line = null; 57 while( (line = br.readLine()) != null) 58 { 59 if( printWriter != null ) 60 { 61 printWriter.println( this.streamIdentifier + line ); 62 printWriter.flush(); 64 } } 66 } 67 catch( IOException ioe ) 68 { 69 ioe.printStackTrace(); 70 } 71 } 73 74 75 } | Popular Tags |