List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry getName
public String getName()
From source file:com.taobao.android.utils.ZipUtils.java
public static List<String> listZipEntries(File zipFile) { List<String> list = new ArrayList<String>(); ZipFile zip;//w ww. ja v a 2 s . com try { zip = new ZipFile(zipFile); Enumeration<ZipArchiveEntry> en = zip.getEntries(); ZipArchiveEntry ze = null; while (en.hasMoreElements()) { ze = en.nextElement(); String name = ze.getName(); list.add(name); } if (null != zip) ZipFile.closeQuietly(zip); } catch (IOException e) { } return list; }
From source file:abfab3d.io.input.ModelLoader.java
private static void unzipEntry(ZipFile zipFile, ZipArchiveEntry entry, File dest) throws IOException { if (entry.isDirectory()) { createDir(new File(dest, entry.getName())); return;//from w w w . j a v a 2 s . c o m } File outputFile = new File(dest, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } BufferedInputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { if (outputStream != null) outputStream.close(); if (inputStream != null) inputStream.close(); } }
From source file:com.taobao.android.utils.ZipUtils.java
/** * <p>/*from ww w . j a v a2s .c om*/ * unzip. * </p> * * @param zipFile a {@link File} object. * @param destination a {@link String} object. * @param encoding a {@link String} object. * @return a {@link List} object. */ public static List<String> unzip(final File zipFile, final String destination, String encoding) { List<String> fileNames = new ArrayList<String>(); String dest = destination; if (!destination.endsWith("/")) { dest = destination + "/"; } ZipFile file; try { file = null; if (null == encoding) file = new ZipFile(zipFile); else file = new ZipFile(zipFile, encoding); Enumeration<ZipArchiveEntry> en = file.getEntries(); ZipArchiveEntry ze = null; while (en.hasMoreElements()) { ze = en.nextElement(); File f = new File(dest, ze.getName()); if (ze.isDirectory()) { f.mkdirs(); continue; } else { f.getParentFile().mkdirs(); InputStream is = file.getInputStream(ze); OutputStream os = new FileOutputStream(f); IOUtils.copy(is, os); is.close(); os.close(); fileNames.add(f.getAbsolutePath()); } } file.close(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return fileNames; }
From source file:com.google.dart.tools.update.core.internal.UpdateUtils.java
/** * Unzip a zip file, notifying the given monitor along the way. *//*ww w . jav a 2s. c om*/ public static void unzip(File zipFile, File destination, String taskName, IProgressMonitor monitor) throws IOException { ZipFile zip = new ZipFile(zipFile); //TODO (pquitslund): add real progress units if (monitor != null) { monitor.beginTask(taskName, 1); } Enumeration<ZipArchiveEntry> e = zip.getEntries(); while (e.hasMoreElements()) { ZipArchiveEntry entry = e.nextElement(); File file = new File(destination, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { InputStream is = zip.getInputStream(entry); File parent = file.getParentFile(); if (parent != null && parent.exists() == false) { parent.mkdirs(); } FileOutputStream os = new FileOutputStream(file); try { IOUtils.copy(is, os); } finally { os.close(); is.close(); } file.setLastModified(entry.getTime()); int mode = entry.getUnixMode(); if ((mode & EXEC_MASK) != 0) { file.setExecutable(true); } } } //TODO (pquitslund): fix progress units if (monitor != null) { monitor.worked(1); monitor.done(); } }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
/** * zip?/*from w ww .java 2s . c o m*/ * * @param zipFile * @param pathName * @return */ public static boolean isFolderExist(File zipFile, String pathName) { ZipFile file = null; try { file = new ZipFile(zipFile); Enumeration<ZipArchiveEntry> en = file.getEntries(); while (en.hasMoreElements()) { ZipArchiveEntry entry = en.nextElement(); String name = entry.getName(); if (name.startsWith(pathName)) { return true; } } return false; } catch (IOException e) { } finally { if (null != file) { try { file.close(); } catch (IOException e) { } } } return false; }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
/** * zip?//from www. j a v a2 s.com * * @param zipFile * @param path * @param destFolder * @throws java.io.IOException */ public static File extractZipFileToFolder(File zipFile, String path, File destFolder) { ZipFile zip; File destFile = null; try { zip = new ZipFile(zipFile); ZipArchiveEntry zipArchiveEntry = zip.getEntry(path); if (null != zipArchiveEntry) { String name = zipArchiveEntry.getName(); name = FilenameUtils.getName(name); destFile = new File(destFolder, name); FileMkUtils.mkdirs(destFolder); destFile.createNewFile(); InputStream is = zip.getInputStream(zipArchiveEntry); FileOutputStream fos = new FileOutputStream(destFile); int length = 0; byte[] b = new byte[1024]; while ((length = is.read(b, 0, 1024)) != -1) { fos.write(b, 0, length); } is.close(); fos.close(); } if (null != zip) { ZipFile.closeQuietly(zip); } } catch (IOException e) { throw new GradleException(e.getMessage(), e); } return destFile; }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
public static List<String> listZipEntries(File zipFile) { List<String> list = new ArrayList<String>(); ZipFile zip;/*from w ww . ja v a 2 s . c o m*/ try { zip = new ZipFile(zipFile); Enumeration<ZipArchiveEntry> en = zip.getEntries(); ZipArchiveEntry ze = null; while (en.hasMoreElements()) { ze = en.nextElement(); String name = ze.getName(); name = StringUtils.replace(name, "/", "."); if (name.endsWith(".class")) { list.add(name); } } if (null != zip) { ZipFile.closeQuietly(zip); } } catch (IOException e) { } return list; }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
/** * <p>/*from w ww.ja v a 2 s . c om*/ * unzip. * </p> * * @param zipFile a {@link java.io.File} object. * @param destination a {@link String} object. * @param encoding a {@link String} object. * @return a {@link java.util.List} object. */ public static List<String> unzip(final File zipFile, final String destination, String encoding) { List<String> fileNames = new ArrayList<String>(); String dest = destination; if (!destination.endsWith(File.separator)) { dest = destination + File.separator; } ZipFile file; try { file = null; if (null == encoding) { file = new ZipFile(zipFile); } else { file = new ZipFile(zipFile, encoding); } Enumeration<ZipArchiveEntry> en = file.getEntries(); ZipArchiveEntry ze = null; while (en.hasMoreElements()) { ze = en.nextElement(); File f = new File(dest, ze.getName()); if (ze.isDirectory()) { f.mkdirs(); continue; } else { f.getParentFile().mkdirs(); InputStream is = file.getInputStream(ze); OutputStream os = new FileOutputStream(f); IOUtils.copy(is, os); is.close(); os.close(); fileNames.add(f.getAbsolutePath()); } } file.close(); } catch (IOException e) { e.printStackTrace(); } return fileNames; }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
public static List<String> unzip(final File zipFile, final String destination, String encoding, Map<String, ZipEntry> zipEntryMethodMap, boolean isRelativePath) { List<String> fileNames = new ArrayList<String>(); String dest = destination;// w w w . j a v a 2 s .com if (!destination.endsWith(File.separator)) { dest = destination + File.separator; } ZipFile file; try { file = null; if (null == encoding) { file = new ZipFile(zipFile); } else { file = new ZipFile(zipFile, encoding); } Enumeration<ZipArchiveEntry> en = file.getEntries(); ZipArchiveEntry ze = null; while (en.hasMoreElements()) { ze = en.nextElement(); File f = new File(dest, ze.getName()); if (ze.isDirectory()) { f.mkdirs(); continue; } else { f.getParentFile().mkdirs(); InputStream is = file.getInputStream(ze); OutputStream os = new FileOutputStream(f); IOUtils.copy(is, os); is.close(); os.close(); fileNames.add(f.getAbsolutePath()); if (zipEntryMethodMap != null && ze.getMethod() == STORED) { zipEntryMethodMap.put(isRelativePath ? ze.getName() : f.getAbsolutePath(), ze); } } } file.close(); } catch (IOException e) { e.printStackTrace(); } return fileNames; }
From source file:com.citytechinc.cq.component.maven.util.ComponentMojoUtil.java
/** * Add files to the already constructed Archive file by creating a new * Archive file, appending the contents of the existing Archive file to it, * and then adding additional entries for the newly constructed artifacts. * //from ww w . j a va2 s .c o m * @param classList * @param classLoader * @param classPool * @param buildDirectory * @param componentPathBase * @param defaultComponentPathSuffix * @param defaultComponentGroup * @param existingArchiveFile * @param tempArchiveFile * @throws OutputFailureException * @throws IOException * @throws InvalidComponentClassException * @throws InvalidComponentFieldException * @throws ParserConfigurationException * @throws TransformerException * @throws ClassNotFoundException * @throws CannotCompileException * @throws NotFoundException * @throws SecurityException * @throws NoSuchFieldException * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws InstantiationException */ public static void buildArchiveFileForProjectAndClassList(List<CtClass> classList, WidgetRegistry widgetRegistry, TouchUIWidgetRegistry touchUIWidgetRegistry, ClassLoader classLoader, ClassPool classPool, File buildDirectory, String componentPathBase, String defaultComponentPathSuffix, String defaultComponentGroup, File existingArchiveFile, File tempArchiveFile, ComponentNameTransformer transformer, boolean generateTouchUiDialogs) throws OutputFailureException, IOException, InvalidComponentClassException, InvalidComponentFieldException, ParserConfigurationException, TransformerException, ClassNotFoundException, CannotCompileException, NotFoundException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException, TouchUIDialogWriteException, TouchUIDialogGenerationException { if (!existingArchiveFile.exists()) { throw new OutputFailureException("Archive file does not exist"); } if (tempArchiveFile.exists()) { tempArchiveFile.delete(); } tempArchiveFile.createNewFile(); deleteTemporaryComponentOutputDirectory(buildDirectory); /* * Create archive input stream */ ZipArchiveInputStream existingInputStream = new ZipArchiveInputStream( new FileInputStream(existingArchiveFile)); /* * Create a zip archive output stream for the temp file */ ZipArchiveOutputStream tempOutputStream = new ZipArchiveOutputStream(tempArchiveFile); /* * Iterate through all existing entries adding them to the new archive */ ZipArchiveEntry curArchiveEntry; Set<String> existingArchiveEntryNames = new HashSet<String>(); while ((curArchiveEntry = existingInputStream.getNextZipEntry()) != null) { existingArchiveEntryNames.add(curArchiveEntry.getName().toLowerCase()); getLog().debug("Current File Name: " + curArchiveEntry.getName()); tempOutputStream.putArchiveEntry(curArchiveEntry); IOUtils.copy(existingInputStream, tempOutputStream); tempOutputStream.closeArchiveEntry(); } /* * Create content.xml within temp archive */ ContentUtil.buildContentFromClassList(classList, tempOutputStream, existingArchiveEntryNames, buildDirectory, componentPathBase, defaultComponentPathSuffix, defaultComponentGroup, transformer); /* * Create Dialogs within temp archive */ DialogUtil.buildDialogsFromClassList(transformer, classList, tempOutputStream, existingArchiveEntryNames, widgetRegistry, classLoader, classPool, buildDirectory, componentPathBase, defaultComponentPathSuffix); if (generateTouchUiDialogs) { TouchUIDialogUtil.buildDialogsFromClassList(classList, classLoader, classPool, touchUIWidgetRegistry, transformer, buildDirectory, componentPathBase, defaultComponentPathSuffix, tempOutputStream, existingArchiveEntryNames); } /* * Create edit config within temp archive */ EditConfigUtil.buildEditConfigFromClassList(classList, tempOutputStream, existingArchiveEntryNames, buildDirectory, componentPathBase, defaultComponentPathSuffix, transformer); /* * Copy temp archive to the original archive position */ tempOutputStream.finish(); existingInputStream.close(); tempOutputStream.close(); existingArchiveFile.delete(); tempArchiveFile.renameTo(existingArchiveFile); }