1 package com.diasparsoftware.java.io; 2 3 import java.io.*; 4 5 public class ReaderUtil { 6 /*** 7 * Obtain a string representation of the content that 8 * a reader reads. 9 * 10 * @param reader 11 * @return 12 * @throws IOException Thrown if an underlying read operation 13 * fails. 14 */ 15 public static String getContentAsString(Reader reader) 16 throws IOException { 17 BufferedReader bufferedReader = new BufferedReader(reader); 18 StringBuffer contentBuffer = new StringBuffer(); 19 20 while (true) { 21 int readResult = bufferedReader.read(); 22 if (readResult == -1) { 23 break; 24 } 25 26 contentBuffer.append((char) readResult); 27 } 28 29 return contentBuffer.toString(); 30 } 31 }