private void zipBarFolder(final File businessArchiveFile, final File folder) throws IOException { // create a ZipOutputStream to zip the data to if (businessArchiveFile.exists()) { throw new IOException("The destination file already exists " + businessArchiveFile.getAbsolutePath()); } final FileOutputStream fileOutput = new FileOutputStream(businessArchiveFile); try (ZipOutputStream zos = new ZipOutputStream(fileOutput)) { IOUtil.zipDir(folder.getAbsolutePath(), zos, folder.getAbsolutePath()); } finally { fileOutput.close(); } }
private void zipBarFolder(final File businessArchiveFile, final File folder) throws IOException { // create a ZipOutputStream to zip the data to if (businessArchiveFile.exists()) { throw new IOException("The destination file already exists " + businessArchiveFile.getAbsolutePath()); } final FileOutputStream fileOutput = new FileOutputStream(businessArchiveFile); try (ZipOutputStream zos = new ZipOutputStream(fileOutput)) { IOUtil.zipDir(folder.getAbsolutePath(), zos, folder.getAbsolutePath()); } finally { fileOutput.close(); } }
public byte[] zip(Folder destFolder) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); try { org.bonitasoft.engine.io.IOUtil.zipDir(this.folder.getAbsolutePath(), zos, destFolder.getFile().getAbsolutePath()); return baos.toByteArray(); } finally { zos.close(); baos.close(); } }
public byte[] zip(Folder destFolder) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); try { org.bonitasoft.engine.io.IOUtil.zipDir(this.folder.getAbsolutePath(), zos, destFolder.getFile().getAbsolutePath()); return baos.toByteArray(); } finally { zos.close(); baos.close(); } }
/** * Create a structured zip archive recursively. * The string must be OS specific String to represent path. * */ public static void zipDir(final String dir2zip, final ZipOutputStream zos, final String root) throws IOException { final File zipDir = new File(dir2zip); final byte[] readBuffer = new byte[BUFFER_SIZE]; for (final String pathName : zipDir.list()) { final File file = new File(zipDir, pathName); final String path = file.getPath(); if (file.isDirectory()) { zipDir(path, zos, root); continue; } try { final ZipEntry anEntry = new ZipEntry(path.substring(root.length() + 1, path.length()).replace(String.valueOf(File.separatorChar), "/")); zos.putNextEntry(anEntry); copyFileToZip(zos, readBuffer, file); zos.flush(); } finally { zos.closeEntry(); } } }
/** * Create a structured zip archive recursively. * The string must be OS specific String to represent path. * */ public static void zipDir(final String dir2zip, final ZipOutputStream zos, final String root) throws IOException { final File zipDir = new File(dir2zip); final byte[] readBuffer = new byte[BUFFER_SIZE]; for (final String pathName : zipDir.list()) { final File file = new File(zipDir, pathName); final String path = file.getPath(); if (file.isDirectory()) { zipDir(path, zos, root); continue; } try { final ZipEntry anEntry = new ZipEntry(path.substring(root.length() + 1, path.length()).replace(String.valueOf(File.separatorChar), "/")); zos.putNextEntry(anEntry); copyFileToZip(zos, readBuffer, file); zos.flush(); } finally { zos.closeEntry(); } } }