@Test public void testUnZip() throws IOException { File tempDir = new File(new File(".").getAbsolutePath() + "/build/temp"); tempDir.mkdirs(); fileUtility.unzip(new File(SRC_TEST_RESOURCES + "instance-template-7.0.55.zip"), tempDir); FileUtils.deleteDirectory(tempDir); }
public void unzip(final File zipFile, final File destination) { if (!destination.exists() && !destination.mkdir()) { throw new FileUtilityException("Failed to create zip file destination directory \"" + destination.getAbsolutePath() + "\"!"); } JarFile jarFile = null; final long startTime = System.currentTimeMillis(); try { LOGGER.debug("Start unzip {}", zipFile.getAbsoluteFile()); jarFile = new JarFile(zipFile); final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = (JarEntry) entries.nextElement(); final File f = new File(destination + File.separator + jarEntry.getName()); if (jarEntry.isDirectory()) { if (!f.mkdirs()) { throw new ApplicationException("Failed to create directory " + f.getAbsoluteFile()); } continue; } final InputStream in = jarFile.getInputStream(jarEntry); final FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bufout = new BufferedOutputStream(fos); while (in.available() > 0) { bufout.write(in.read()); } bufout.close(); in.close(); } } catch (final IOException e) { throw new FileUtilityException("Failed to unpack " + zipFile.getAbsolutePath() + "!", e); } finally { closeJarFile(jarFile); LOGGER.debug("End unzip {} in {} ms", zipFile.getAbsoluteFile(), (System.currentTimeMillis() - startTime)); } }
FileUtility { public void unzip(final File zipFile, final File destination) { if (!destination.exists() && !destination.mkdir()) { throw new FileUtilityException("Failed to create zip file destination directory \"" + destination.getAbsolutePath() + "\"!"); } JarFile jarFile = null; final long startTime = System.currentTimeMillis(); try { LOGGER.debug("Start unzip {}", zipFile.getAbsoluteFile()); jarFile = new JarFile(zipFile); final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = (JarEntry) entries.nextElement(); final File f = new File(destination + File.separator + jarEntry.getName()); if (jarEntry.isDirectory()) { if (!f.mkdirs()) { throw new ApplicationException("Failed to create directory " + f.getAbsoluteFile()); } continue; } final InputStream in = jarFile.getInputStream(jarEntry); final FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bufout = new BufferedOutputStream(fos); while (in.available() > 0) { bufout.write(in.read()); } bufout.close(); in.close(); } } catch (final IOException e) { throw new FileUtilityException("Failed to unpack " + zipFile.getAbsolutePath() + "!", e); } finally { closeJarFile(jarFile); LOGGER.debug("End unzip {} in {} ms", zipFile.getAbsoluteFile(), (System.currentTimeMillis() - startTime)); } } }
FileUtility { public void unzip(final File zipFile, final File destination) { if (!destination.exists() && !destination.mkdir()) { throw new FileUtilityException("Failed to create zip file destination directory \"" + destination.getAbsolutePath() + "\"!"); } JarFile jarFile = null; final long startTime = System.currentTimeMillis(); try { LOGGER.debug("Start unzip {}", zipFile.getAbsoluteFile()); jarFile = new JarFile(zipFile); final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = (JarEntry) entries.nextElement(); final File f = new File(destination + File.separator + jarEntry.getName()); if (jarEntry.isDirectory()) { if (!f.mkdirs()) { throw new ApplicationException("Failed to create directory " + f.getAbsoluteFile()); } continue; } final InputStream in = jarFile.getInputStream(jarEntry); final FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bufout = new BufferedOutputStream(fos); while (in.available() > 0) { bufout.write(in.read()); } bufout.close(); in.close(); } } catch (final IOException e) { throw new FileUtilityException("Failed to unpack " + zipFile.getAbsolutePath() + "!", e); } finally { closeJarFile(jarFile); LOGGER.debug("End unzip {} in {} ms", zipFile.getAbsoluteFile(), (System.currentTimeMillis() - startTime)); } }  }
FileUtility { public void unzip(final File zipFile, final File destination) { if (!destination.exists() && !destination.mkdir()) { throw new FileUtilityException("Failed to create zip file destination directory \"" + destination.getAbsolutePath() + "\"!"); } JarFile jarFile = null; final long startTime = System.currentTimeMillis(); try { LOGGER.debug("Start unzip {}", zipFile.getAbsoluteFile()); jarFile = new JarFile(zipFile); final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = (JarEntry) entries.nextElement(); final File f = new File(destination + File.separator + jarEntry.getName()); if (jarEntry.isDirectory()) { if (!f.mkdirs()) { throw new ApplicationException("Failed to create directory " + f.getAbsoluteFile()); } continue; } final InputStream in = jarFile.getInputStream(jarEntry); final FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bufout = new BufferedOutputStream(fos); while (in.available() > 0) { bufout.write(in.read()); } bufout.close(); in.close(); } } catch (final IOException e) { throw new FileUtilityException("Failed to unpack " + zipFile.getAbsolutePath() + "!", e); } finally { closeJarFile(jarFile); LOGGER.debug("End unzip {} in {} ms", zipFile.getAbsoluteFile(), (System.currentTimeMillis() - startTime)); } }  void unzip(final File zipFile, final File destination); Set<String> getZipRootDirs(final String zipFilename); void createJarArchive(File archiveFile, File[] filesToBeJared, String parent); static Set<String> getGZipRootDirs(String tarGzipFile); static String getCheckSum(final String fileAbsolutePath); }
FileUtility { public void unzip(final File zipFile, final File destination) { if (!destination.exists() && !destination.mkdir()) { throw new FileUtilityException("Failed to create zip file destination directory \"" + destination.getAbsolutePath() + "\"!"); } JarFile jarFile = null; final long startTime = System.currentTimeMillis(); try { LOGGER.debug("Start unzip {}", zipFile.getAbsoluteFile()); jarFile = new JarFile(zipFile); final Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry jarEntry = (JarEntry) entries.nextElement(); final File f = new File(destination + File.separator + jarEntry.getName()); if (jarEntry.isDirectory()) { if (!f.mkdirs()) { throw new ApplicationException("Failed to create directory " + f.getAbsoluteFile()); } continue; } final InputStream in = jarFile.getInputStream(jarEntry); final FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bufout = new BufferedOutputStream(fos); while (in.available() > 0) { bufout.write(in.read()); } bufout.close(); in.close(); } } catch (final IOException e) { throw new FileUtilityException("Failed to unpack " + zipFile.getAbsolutePath() + "!", e); } finally { closeJarFile(jarFile); LOGGER.debug("End unzip {} in {} ms", zipFile.getAbsoluteFile(), (System.currentTimeMillis() - startTime)); } }  void unzip(final File zipFile, final File destination); Set<String> getZipRootDirs(final String zipFilename); void createJarArchive(File archiveFile, File[] filesToBeJared, String parent); static Set<String> getGZipRootDirs(String tarGzipFile); static String getCheckSum(final String fileAbsolutePath);  }