OutputWriterHelper { static void copyToStream(File file, OutputStream out) throws IOException { try (InputStream in = new FileInputStream(file)) { IOUtils.copy(in, out); } finally { delete(file); } } private  OutputWriterHelper();   }
@Test public void copyStreamSingleFile() throws IOException { File tempFile = folder.newFile(); Map<String, File> files = new HashMap<String, File>(); files.put("newName", tempFile); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputWriterHelper.copyToStream(files.values().iterator().next(), out); assertFalse("temporary file not deleted", tempFile.exists()); assertEquals(out.size(), tempFile.length()); }