@Test public void testUnzip() throws Exception { ZipUtil.unzip(sampleZip, destDir); ZipFile test = new ZipFile(sampleZip); Enumeration<? extends ZipEntry> entries = test.entries(); try { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); Assert.assertTrue(new File(destDir, entry.getName()).exists()); } } catch (AssertionError ae) { test.close(); throw ae; } test.close(); }
public static void unzip(java.io.File zipFile, java.io.File destination) throws IOException { boolean success; if (zipFile == null) { logger.error("The zip file cannot be null"); throw new IllegalArgumentException("The zip file must be set"); } if (!zipFile.exists()) { logger.error("The zip file does not exist: {}", zipFile.getCanonicalPath()); throw new FileNotFoundException("The zip file does not exist: " + zipFile.getCanonicalPath()); } if (destination == null) { logger.error("The destination file cannot be null"); throw new IllegalArgumentException("Destination file cannot be null"); } File f; try { f = new File(zipFile.getCanonicalFile()); } catch (IOException ioe) { logger.error("Unable to create the zip file: {}", destination.getAbsolutePath()); throw new IOException("Unable to create the zip file: {}" + destination.getAbsolutePath(), ioe); } try { if (f.isArchive() && f.isDirectory()) { if (destination.exists()) { if (!destination.isDirectory()) { logger.error("Destination file must be a directory"); throw new IllegalArgumentException("Destination file must be a directory"); } } try { destination.mkdirs(); } catch (SecurityException e) { logger.error("Cannot create destination directory: {}", e.getMessage()); throw new IOException("Cannot create destination directory", e); } success = f.copyAllTo(destination); if (success) logger.debug("File {} unzipped successfully", zipFile.getCanonicalPath()); else { logger.warn("File {} was not correctly unzipped", zipFile.getCanonicalPath()); throw new IOException("File " + zipFile.getCanonicalPath() + " was not correctly unzipped"); } } else { logger.error("The input file is not a valid zip file"); throw new IllegalArgumentException("The input file is not a valid zip file"); } } catch (IOException e) { throw (e); } finally { umount(f); } }
ZipUtil { public static void unzip(java.io.File zipFile, java.io.File destination) throws IOException { boolean success; if (zipFile == null) { logger.error("The zip file cannot be null"); throw new IllegalArgumentException("The zip file must be set"); } if (!zipFile.exists()) { logger.error("The zip file does not exist: {}", zipFile.getCanonicalPath()); throw new FileNotFoundException("The zip file does not exist: " + zipFile.getCanonicalPath()); } if (destination == null) { logger.error("The destination file cannot be null"); throw new IllegalArgumentException("Destination file cannot be null"); } File f; try { f = new File(zipFile.getCanonicalFile()); } catch (IOException ioe) { logger.error("Unable to create the zip file: {}", destination.getAbsolutePath()); throw new IOException("Unable to create the zip file: {}" + destination.getAbsolutePath(), ioe); } try { if (f.isArchive() && f.isDirectory()) { if (destination.exists()) { if (!destination.isDirectory()) { logger.error("Destination file must be a directory"); throw new IllegalArgumentException("Destination file must be a directory"); } } try { destination.mkdirs(); } catch (SecurityException e) { logger.error("Cannot create destination directory: {}", e.getMessage()); throw new IOException("Cannot create destination directory", e); } success = f.copyAllTo(destination); if (success) logger.debug("File {} unzipped successfully", zipFile.getCanonicalPath()); else { logger.warn("File {} was not correctly unzipped", zipFile.getCanonicalPath()); throw new IOException("File " + zipFile.getCanonicalPath() + " was not correctly unzipped"); } } else { logger.error("The input file is not a valid zip file"); throw new IllegalArgumentException("The input file is not a valid zip file"); } } catch (IOException e) { throw (e); } finally { umount(f); } } }
ZipUtil { public static void unzip(java.io.File zipFile, java.io.File destination) throws IOException { boolean success; if (zipFile == null) { logger.error("The zip file cannot be null"); throw new IllegalArgumentException("The zip file must be set"); } if (!zipFile.exists()) { logger.error("The zip file does not exist: {}", zipFile.getCanonicalPath()); throw new FileNotFoundException("The zip file does not exist: " + zipFile.getCanonicalPath()); } if (destination == null) { logger.error("The destination file cannot be null"); throw new IllegalArgumentException("Destination file cannot be null"); } File f; try { f = new File(zipFile.getCanonicalFile()); } catch (IOException ioe) { logger.error("Unable to create the zip file: {}", destination.getAbsolutePath()); throw new IOException("Unable to create the zip file: {}" + destination.getAbsolutePath(), ioe); } try { if (f.isArchive() && f.isDirectory()) { if (destination.exists()) { if (!destination.isDirectory()) { logger.error("Destination file must be a directory"); throw new IllegalArgumentException("Destination file must be a directory"); } } try { destination.mkdirs(); } catch (SecurityException e) { logger.error("Cannot create destination directory: {}", e.getMessage()); throw new IOException("Cannot create destination directory", e); } success = f.copyAllTo(destination); if (success) logger.debug("File {} unzipped successfully", zipFile.getCanonicalPath()); else { logger.warn("File {} was not correctly unzipped", zipFile.getCanonicalPath()); throw new IOException("File " + zipFile.getCanonicalPath() + " was not correctly unzipped"); } } else { logger.error("The input file is not a valid zip file"); throw new IllegalArgumentException("The input file is not a valid zip file"); } } catch (IOException e) { throw (e); } finally { umount(f); } } private  ZipUtil(); }
ZipUtil { public static void unzip(java.io.File zipFile, java.io.File destination) throws IOException { boolean success; if (zipFile == null) { logger.error("The zip file cannot be null"); throw new IllegalArgumentException("The zip file must be set"); } if (!zipFile.exists()) { logger.error("The zip file does not exist: {}", zipFile.getCanonicalPath()); throw new FileNotFoundException("The zip file does not exist: " + zipFile.getCanonicalPath()); } if (destination == null) { logger.error("The destination file cannot be null"); throw new IllegalArgumentException("Destination file cannot be null"); } File f; try { f = new File(zipFile.getCanonicalFile()); } catch (IOException ioe) { logger.error("Unable to create the zip file: {}", destination.getAbsolutePath()); throw new IOException("Unable to create the zip file: {}" + destination.getAbsolutePath(), ioe); } try { if (f.isArchive() && f.isDirectory()) { if (destination.exists()) { if (!destination.isDirectory()) { logger.error("Destination file must be a directory"); throw new IllegalArgumentException("Destination file must be a directory"); } } try { destination.mkdirs(); } catch (SecurityException e) { logger.error("Cannot create destination directory: {}", e.getMessage()); throw new IOException("Cannot create destination directory", e); } success = f.copyAllTo(destination); if (success) logger.debug("File {} unzipped successfully", zipFile.getCanonicalPath()); else { logger.warn("File {} was not correctly unzipped", zipFile.getCanonicalPath()); throw new IOException("File " + zipFile.getCanonicalPath() + " was not correctly unzipped"); } } else { logger.error("The input file is not a valid zip file"); throw new IllegalArgumentException("The input file is not a valid zip file"); } } catch (IOException e) { throw (e); } finally { umount(f); } } private  ZipUtil(); static java.io.File zip(java.io.File[] sourceFiles, java.io.File destination, boolean recursive, int level); static void unzip(java.io.File zipFile, java.io.File destination); static java.io.File zip(String[] sourceFiles, String destination, boolean recursive, int level); static java.io.File zip(String[] sourceFiles, java.io.File destination, boolean recursive, int level); static java.io.File zip(java.io.File[] sourceFiles, String destination, boolean recursive, int level); static java.io.File zip(java.io.File[] sourceFiles, java.io.File destination, int level); static void unzip(String zipFile, String destination); static void unzip(java.io.File zipFile, String destination); static void unzip(String zipFile, java.io.File destination); }
ZipUtil { public static void unzip(java.io.File zipFile, java.io.File destination) throws IOException { boolean success; if (zipFile == null) { logger.error("The zip file cannot be null"); throw new IllegalArgumentException("The zip file must be set"); } if (!zipFile.exists()) { logger.error("The zip file does not exist: {}", zipFile.getCanonicalPath()); throw new FileNotFoundException("The zip file does not exist: " + zipFile.getCanonicalPath()); } if (destination == null) { logger.error("The destination file cannot be null"); throw new IllegalArgumentException("Destination file cannot be null"); } File f; try { f = new File(zipFile.getCanonicalFile()); } catch (IOException ioe) { logger.error("Unable to create the zip file: {}", destination.getAbsolutePath()); throw new IOException("Unable to create the zip file: {}" + destination.getAbsolutePath(), ioe); } try { if (f.isArchive() && f.isDirectory()) { if (destination.exists()) { if (!destination.isDirectory()) { logger.error("Destination file must be a directory"); throw new IllegalArgumentException("Destination file must be a directory"); } } try { destination.mkdirs(); } catch (SecurityException e) { logger.error("Cannot create destination directory: {}", e.getMessage()); throw new IOException("Cannot create destination directory", e); } success = f.copyAllTo(destination); if (success) logger.debug("File {} unzipped successfully", zipFile.getCanonicalPath()); else { logger.warn("File {} was not correctly unzipped", zipFile.getCanonicalPath()); throw new IOException("File " + zipFile.getCanonicalPath() + " was not correctly unzipped"); } } else { logger.error("The input file is not a valid zip file"); throw new IllegalArgumentException("The input file is not a valid zip file"); } } catch (IOException e) { throw (e); } finally { umount(f); } } private  ZipUtil(); static java.io.File zip(java.io.File[] sourceFiles, java.io.File destination, boolean recursive, int level); static void unzip(java.io.File zipFile, java.io.File destination); static java.io.File zip(String[] sourceFiles, String destination, boolean recursive, int level); static java.io.File zip(String[] sourceFiles, java.io.File destination, boolean recursive, int level); static java.io.File zip(java.io.File[] sourceFiles, String destination, boolean recursive, int level); static java.io.File zip(java.io.File[] sourceFiles, java.io.File destination, int level); static void unzip(String zipFile, String destination); static void unzip(java.io.File zipFile, String destination); static void unzip(String zipFile, java.io.File destination); static final int BEST_SPEED; static final int BEST_COMPRESSION; static final int DEFAULT_COMPRESSION; static final int NO_COMPRESSION; }