1 20 package org.apache.cactus.internal.util; 21 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 27 32 public class IoUtil 33 { 34 37 public static String getText(InputStream theStream) throws IOException 38 { 39 return getText(theStream, null); 40 } 41 42 51 public static String getText(InputStream theStream, String theCharsetName) 52 throws IOException 53 { 54 StringBuffer sb = new StringBuffer (); 55 56 BufferedReader input; 57 if (theCharsetName == null) 58 { 59 input = new BufferedReader (new InputStreamReader (theStream)); 60 } 61 else 62 { 63 input = new BufferedReader ( 64 new InputStreamReader (theStream, theCharsetName)); 65 } 66 67 char[] buffer = new char[2048]; 68 int nb; 69 70 while (-1 != (nb = input.read(buffer, 0, 2048))) 71 { 72 sb.append(buffer, 0, nb); 73 } 74 75 input.close(); 76 77 return sb.toString(); 78 } 79 } 80 | Popular Tags |