InputStreamArchiveFile extends ArchiveFile { public File copyStreamToDirectory(String directory) throws IOException { File tempFile = new File(directory + "/" + fileName); FileOutputStream fos = null; try { fos = new FileOutputStream(tempFile); fos.write(streamData.clone()); } finally { fos.close(); } return tempFile; } InputStreamArchiveFile(String mimeType, String location, InputStream stream); InputStream toStream(); File copyStreamToDirectory(String directory);  }
@Test public void test_copy_stream_to_file() throws IOException { InputStream inputStream = new FileInputStream(new File(TEST_DIRECTORY + "/" + FILE_NAME)); ArchiveFile af = new InputStreamArchiveFile("mime", FILE_NAME, inputStream); String tempDirectory = "src/test/resources/temp"; File tempFile = new File(tempDirectory + "/" + FILE_NAME); if (tempFile.exists()) tempFile.delete(); af.copyStreamToDirectory(tempDirectory); assertThat(tempFile.exists(), is(true)); }