String to InputStream

Setup

private static final String PHRASE = "like turkeys voting for (an early) Christmas";

Straight up Java

@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);
}

Google Guava

@Test
public void convert_string_to_inputstream_guava () {
    // https://code.google.com/p/guava-libraries/issues/detail?id=642
}

Apache Commons

@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);
}