1 4 package com.tc.admin.common; 5 6 import org.apache.commons.io.IOUtils; 7 8 import java.io.BufferedReader ; 9 import java.io.InputStream ; 10 import java.io.InputStreamReader ; 11 12 16 17 public class InputStreamDrainer extends Thread { 18 private InputStream m_stream; 19 private StringBuffer m_buffer; 20 21 private static final String LINE_SEP = System.getProperty("line.separator"); 22 23 public InputStreamDrainer(InputStream stream) { 24 m_stream = stream; 25 } 26 27 public void run() { 28 InputStreamReader streamReader = new InputStreamReader (m_stream); 29 BufferedReader bufferedReader = new BufferedReader (streamReader); 30 String line; 31 32 m_buffer = new StringBuffer (); 33 34 while(true) { 35 try { 36 if((line = bufferedReader.readLine()) == null) { 37 IOUtils.closeQuietly(bufferedReader); 38 return; 39 } 40 m_buffer.append(line+LINE_SEP); 41 } catch(Exception e) { 42 IOUtils.closeQuietly(bufferedReader); 43 return; 44 } 45 } 46 } 47 48 public String getBufferContent() { 49 return m_buffer.toString(); 50 } 51 } 52 | Popular Tags |