IOUtil { public static String readStringFromStream(InputStream stream) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(stream, writer, "UTF-8"); stream.close(); return writer.toString(); } private  IOUtil(); static String readStringFromStream(InputStream stream); static InputStream writeStringToStream(String string); static OutputStream getOutputStream(File file); static void copy(InputStream input, OutputStream output); static void copyFileToDirectory(File file, File dir); static void fileFindReplace(File file, String find, String replace); static File writeStreamToFile(InputStream inStream); static File writeStreamToFile(InputStream inStream, boolean gzip); static InputStream getFileStream(File file); static void addFileToZipOutputStream(File file, ZipOutputStream zipOs);  }
@Test public void testReadStringFromStream() throws Exception { String testValue = "This is a testing string"; InputStream testStream = new ByteArrayInputStream(testValue.getBytes("UTF-8")); String readValue = IOUtil.readStringFromStream(testStream); assertTrue(testValue.equals(readValue)); }