@Test
public void testStreamToFile() throws Exception {

    String test = "test";
    ByteArrayInputStream bais = new ByteArrayInputStream(test.getBytes());
    Misc.streamToFile(bais, file);
    // to read from the file
    InputStream is = new FileInputStream(file);
    BufferedReader buf = new BufferedReader(new InputStreamReader(is));
    String line = buf.readLine();
    StringBuilder sb = new StringBuilder();
    while (line != null) {
        sb.append(line).append("\n");
        line = buf.readLine();
    }
    buf.close();
    String fileAsString = sb.toString();
    assertEquals("test\n", fileAsString);
}