private static void recursiveZip(final ZipOutputStream zos, final File root, final File base) throws IOException { final String[] dirList = base.list(); for (final String element : dirList) { final File f = new File(base, element); if (f.isDirectory()) { recursiveZip(zos, root, f); } else { final FileInputStream fis = new FileInputStream(f); try { if (!FilenameUtils.isExtension(f.getName(), Arrays.asList("js", "coffee", "ts", "json", "css", "less"))) { writeDeflate(f, fis, zos, root); } else { writeStored(f, fis, zos, root); } } finally { IOUtils.closeQuietly(fis); } } } }
/** * @param out * The output stream to write to * @param dir * The directory to zip * @throws IOException */ public static void zip(final OutputStream out, final File dir) throws IOException { final ZipOutputStream zos = new ZipOutputStream(out); recursiveZip(zos, dir, dir); zos.close(); }
/** * @param target * @param bytes * @throws ExecutionException */ public void unzip(final File target, final byte[] bytes) throws ExecutionException { try { final File temp = File.createTempFile("smaller", ".zip"); temp.delete(); final FileOutputStream fos = new FileOutputStream(temp); try { IOUtils.write(bytes, fos); target.mkdirs(); Zip.unzip(temp, target); } finally { IOUtils.closeQuietly(fos); if (!this.debug) { temp.delete(); } else { this.logger.debug("Path to output files: " + temp); } } } catch (final IOException e) { throw new ExecutionException("Failed to handle smaller response", e); } }
FileUtils.copyFile(new File(base, pd.getInputFile()), target); Zip.zip(baos, temp); } finally { if (!this.debug) {