@Test public void badInputUnzipStrStr() throws Exception { File destFile = new File(destDir, "badInputStrStr"); try { try { ZipUtil.unzip((String) null, destFile.getCanonicalPath()); logger.error("Unzip should fail when input filename is null"); Assert.fail("Unzip should fail when input filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input filename (String, String): OK"); } try { ZipUtil.unzip("", destFile.getCanonicalPath()); logger.error("Unzip should fail when input filename is empty"); Assert.fail("Unzip should fail when input filename is empty"); } catch (IllegalArgumentException e) { logger.debug("Detecting empty input filename (String, String): OK"); } try { ZipUtil.unzip(sampleZip.getCanonicalPath(), (String) null); logger.error("Unzip should fail when destination filename is null"); Assert.fail("Unzip should fail when destination filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination filename (String, String): OK"); } try { ZipUtil.unzip(sampleZip.getCanonicalPath(), ""); logger.error("Unzip should fail when destination filename is empty"); Assert.fail("Unzip should fail when destination filename is empty"); } catch (IllegalArgumentException e) { logger.debug("Detecting empty destination filename (String, String): OK"); } try { ZipUtil.unzip(dummieFile.getCanonicalPath(), destFile.getCanonicalPath()); logger.error("Unzip should fail when the input filename doesn't exists"); Assert.fail("Unzip should fail when the input filename doesn't exists"); } catch (FileNotFoundException e) { logger.debug("Detecting existing input filename (String, String): OK"); } try { ZipUtil.unzip(srcFile.getCanonicalPath(), destFile.getCanonicalPath()); logger.error("Unzip should fail when the input filename does not represent a zip file"); Assert.fail("Unzip should fail when the input filename does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting input filename not representing a valid zip file (String, String): OK"); } try { ZipUtil.unzip(sampleZip.getCanonicalPath(), srcFile.getCanonicalPath()); logger.error("Unzip should fail when the destination filename does not represent a directory"); Assert.fail("Unzip should fail when the destination filename does not represent a directory"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination filename not representing a directory (String, String): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + "instead: " + e.getMessage()); } }
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; }