@Test public void copyStreamZipped() throws IOException { File tempFile = folder.newFile(); Map<String, File> files = new HashMap<String, File>(); files.put("newName", tempFile); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputWriterHelper.copyToStreamZipped(files, out); assertFalse("temporary file not deleted", tempFile.exists()); assertTrue(out.size() > 0); }
static void copyToStreamZipped(Map<String, File> files, OutputStream out) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(out)) { for (Entry<String, File> entry : files.entrySet()) { if (isBlank(entry.getKey())) { throw new IOException(String.format( "Unable to copy %s to the output stream, no output name specified.", entry.getValue())); } try (FileInputStream input = new FileInputStream(entry.getValue())) { zipOut.putNextEntry(new ZipEntry(entry.getKey())); LOG.debug("Copying {} to zip stream {}.", entry.getValue(), entry.getKey()); IOUtils.copy(input, zipOut); } finally { delete(entry.getValue()); } } } }
OutputWriterHelper { static void copyToStreamZipped(Map<String, File> files, OutputStream out) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(out)) { for (Entry<String, File> entry : files.entrySet()) { if (isBlank(entry.getKey())) { throw new IOException(String.format( "Unable to copy %s to the output stream, no output name specified.", entry.getValue())); } try (FileInputStream input = new FileInputStream(entry.getValue())) { zipOut.putNextEntry(new ZipEntry(entry.getKey())); LOG.debug("Copying {} to zip stream {}.", entry.getValue(), entry.getKey()); IOUtils.copy(input, zipOut); } finally { delete(entry.getValue()); } } } } }
OutputWriterHelper { static void copyToStreamZipped(Map<String, File> files, OutputStream out) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(out)) { for (Entry<String, File> entry : files.entrySet()) { if (isBlank(entry.getKey())) { throw new IOException(String.format( "Unable to copy %s to the output stream, no output name specified.", entry.getValue())); } try (FileInputStream input = new FileInputStream(entry.getValue())) { zipOut.putNextEntry(new ZipEntry(entry.getKey())); LOG.debug("Copying {} to zip stream {}.", entry.getValue(), entry.getKey()); IOUtils.copy(input, zipOut); } finally { delete(entry.getValue()); } } } } private  OutputWriterHelper(); }
OutputWriterHelper { static void copyToStreamZipped(Map<String, File> files, OutputStream out) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(out)) { for (Entry<String, File> entry : files.entrySet()) { if (isBlank(entry.getKey())) { throw new IOException(String.format( "Unable to copy %s to the output stream, no output name specified.", entry.getValue())); } try (FileInputStream input = new FileInputStream(entry.getValue())) { zipOut.putNextEntry(new ZipEntry(entry.getKey())); LOG.debug("Copying {} to zip stream {}.", entry.getValue(), entry.getKey()); IOUtils.copy(input, zipOut); } finally { delete(entry.getValue()); } } } } private  OutputWriterHelper();  }
OutputWriterHelper { static void copyToStreamZipped(Map<String, File> files, OutputStream out) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(out)) { for (Entry<String, File> entry : files.entrySet()) { if (isBlank(entry.getKey())) { throw new IOException(String.format( "Unable to copy %s to the output stream, no output name specified.", entry.getValue())); } try (FileInputStream input = new FileInputStream(entry.getValue())) { zipOut.putNextEntry(new ZipEntry(entry.getKey())); LOG.debug("Copying {} to zip stream {}.", entry.getValue(), entry.getKey()); IOUtils.copy(input, zipOut); } finally { delete(entry.getValue()); } } } } private  OutputWriterHelper();   }