private static final String PHRASE = "like turkeys voting for (an early) Christmas";
@Test public void convert_string_to_inputstream () throws IOException { InputStream inputStream = new ByteArrayInputStream(PHRASE.getBytes()); // now to do some work w/ it StringBuffer phraseThroughStream = new StringBuffer(); int c; while ((c = inputStream.read()) != -1) { phraseThroughStream.append((char) c); } assertEquals(phraseThroughStream.toString(), PHRASE); }
@Test public void convert_string_to_inputstream_guava () { // https://code.google.com/p/guava-libraries/issues/detail?id=642 }
@Test public void convert_string_to_inputstream_apache () throws IOException { InputStream inputStream = IOUtils.toInputStream(PHRASE); // now to do some work w/ it StringBuffer phraseThroughStream = new StringBuffer(); int c; while ((c = inputStream.read()) != -1) { phraseThroughStream.append((char) c); } assertEquals(phraseThroughStream.toString(), PHRASE); }