IOUtil { public static InputStream writeStringToStream(String string) throws IOException { return IOUtils.toInputStream(string, "UTF-8"); } 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 testWriteStringToStream() throws Exception { String testValue = "This is a testing string"; InputStream testStream = IOUtil.writeStringToStream(testValue); byte[] bytes = new byte[testValue.getBytes().length]; testStream.read(bytes); String readValue = new String(bytes, "UTF-8"); assertTrue(testValue.equals(readValue)); }