Example usage for java.util.zip ZipEntry getName

List of usage examples for java.util.zip ZipEntry getName

Introduction

In this page you can find the example usage for java.util.zip ZipEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entry.

Usage

From source file:com.gettingagile.tisugly.analyzer.ASMAnalyzer.java

private void loadClassesFromClasspathArchiveFile(File classpathElement) throws IOException {
    ZipFile f = new ZipFile(classpathElement.getAbsolutePath());
    Enumeration<? extends ZipEntry> en = f.entries();
    while (en.hasMoreElements()) {
        ZipEntry e = en.nextElement();
        String name = e.getName();
        if (name.endsWith(".class")) {
            new ClassReader(f.getInputStream(e)).accept(dependencyVisitor, 0);
        }/*  w  ww .  j ava 2 s .c o  m*/
    }
}

From source file:com.clank.launcher.install.ZipExtract.java

/**
 * Checks if the given entry should be extracted.
 *
 * @param entry the entry/*from   www  .ja v a2  s  . com*/
 * @return true if the entry matches the filter
 */
private boolean matches(ZipEntry entry) {
    if (exclude != null) {
        for (String pattern : exclude) {
            if (entry.getName().startsWith(pattern)) {
                return false;
            }
        }
    }

    return true;
}

From source file:org.openmrs.module.clinicalsummary.rule.EvaluableSummaryRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *//*from   w w w .  j  a  v  a2  s. c  o m*/
@Override
public void afterStartup() {

    if (log.isDebugEnabled())
        log.debug("Registering clinical summary rules ...");

    try {
        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(CLINICAL_SUMMARY_MODULE);
        for (URL url : moduleClassLoader.getURLs()) {
            String filename = url.getFile();
            if (StringUtils.contains(filename, CLINICAL_SUMMARY_MODULE_API)) {
                ZipFile zipFile = new ZipFile(filename);
                for (Enumeration list = zipFile.entries(); list.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) list.nextElement();
                    String zipFileName = FilenameUtils.getBaseName(entry.getName());
                    String zipFileExtension = FilenameUtils.getExtension(entry.getName());
                    if (StringUtils.endsWith(zipFileName, RULE_CLASS_SUFFIX)
                            && StringUtils.equals(zipFileExtension, CLASS_SUFFIX)) {
                        EvaluableRuleVisitor visitor = new EvaluableRuleVisitor();
                        ClassReader classReader = new ClassReader(zipFile.getInputStream(entry));
                        classReader.accept(visitor, false);
                    }
                }
                zipFile.close();
            }
        }
    } catch (IOException e) {
        log.error("Processing rule classes failed. Rule might not get registered.");
    }
}

From source file:de.thischwa.pmcms.server.ZipProxyServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    zipPathToSkip = config.getInitParameter("zipPathToSkip");
    String fileParam = config.getInitParameter("file");
    if (StringUtils.isBlank(fileParam))
        throw new IllegalArgumentException("No file parameter found!");
    File file = null;//ww w . ja v a2  s .c o m
    zipInfo = new HashMap<String, ZipEntry>();
    try {
        file = new File(config.getInitParameter("file"));
        if (!file.exists()) {
            throw new ServletException(String.format("Zip-file not found: %s", file.getPath()));
        }
        zipFile = new ZipFile(file);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry ze = entries.nextElement();
            String entryName = ze.getName();
            if (zipPathToSkip != null)
                entryName = entryName.substring(zipPathToSkip.length() + 1);
            if (entryName.startsWith("/"))
                entryName = entryName.substring(1);
            zipInfo.put(entryName, ze);
        }
        logger.debug("Found entries in zip: " + zipInfo.size());
    } catch (IOException e) {
        throw new ServletException("Couldn't read the zip file: " + e.getMessage(), e);
    }
    logger.info(String.format("ZipProxyServlet initialzed with file [%s] and path to skip [%s]", file.getPath(),
            zipPathToSkip));
}

From source file:org.openmrs.module.amrsreports.rule.MohEvaluableRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *///w  w w  . j  a  va  2 s. com
@Override
public void afterStartup() {

    if (log.isDebugEnabled())
        log.debug("Registering AMRS reports summary rules ...");

    try {
        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(AMRS_REPORT_MODULE);
        for (URL url : moduleClassLoader.getURLs()) {
            String filename = url.getFile();
            if (StringUtils.contains(filename, AMRS_REPORT_MODULE_API)) {
                ZipFile zipFile = new ZipFile(filename);
                for (Enumeration list = zipFile.entries(); list.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) list.nextElement();
                    String zipFileName = FilenameUtils.getBaseName(entry.getName());
                    String zipFileExtension = FilenameUtils.getExtension(entry.getName());
                    if (StringUtils.endsWith(zipFileName, RULE_CLASS_SUFFIX)
                            && StringUtils.equals(zipFileExtension, CLASS_SUFFIX)) {
                        MohEvaluableRuleVisitor visitor = new MohEvaluableRuleVisitor();
                        ClassReader classReader = new ClassReader(zipFile.getInputStream(entry));
                        classReader.accept(visitor, false);
                    }
                }
                zipFile.close();
            }
        }
    } catch (IOException e) {
        log.error("Processing rule classes failed. Rule might not get registered.");
    }
}

From source file:be.fedict.eid.applet.service.signer.asic.ASiCSignatureOutputStream.java

@Override
public void close() throws IOException {
    super.close();

    byte[] signatureData = toByteArray();

    /*//  ww  w.j  a  v  a  2 s  . c o m
     * Copy the original ZIP content.
     */
    ZipOutputStream zipOutputStream = new ZipOutputStream(this.targetOutputStream);
    ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(this.originalZipFile));
    ZipEntry zipEntry;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (!zipEntry.getName().equals(ASiCUtil.SIGNATURE_FILE)) {
            ZipEntry newZipEntry = new ZipEntry(zipEntry.getName());
            zipOutputStream.putNextEntry(newZipEntry);
            LOG.debug("copying " + zipEntry.getName());
            IOUtils.copy(zipInputStream, zipOutputStream);
        }
    }
    zipInputStream.close();

    /*
     * Add the XML signature file to the ASiC package.
     */
    zipEntry = new ZipEntry(ASiCUtil.SIGNATURE_FILE);
    LOG.debug("writing " + zipEntry.getName());
    zipOutputStream.putNextEntry(zipEntry);
    IOUtils.write(signatureData, zipOutputStream);
    zipOutputStream.close();
}

From source file:com.jaromin.alfresco.repo.content.transform.ZipFormatContentTransformer.java

/**
 * //from   w  ww.  j  av a  2 s. com
 * @param path
 * @param zip
 * @param out
 * @throws IOException
 */
protected void extractEntry(String path, ZipInputStream zip, OutputStream out) throws IOException {

    // Use as regex for more flexibility...
    Pattern p = Pattern.compile(path);

    ZipEntry entry = null;
    while ((entry = zip.getNextEntry()) != null) {
        Matcher m = p.matcher(entry.getName());
        if (m.matches()) {
            IOUtils.copy(zip, out);
            zip.closeEntry();
            break;
        }
    }
}

From source file:gdt.data.entity.ArchiveHandler.java

private static boolean hasPropertyIndexInZipStream(ZipInputStream zis) {
    try {/*from   w ww.java  2s.  com*/
        ZipEntry entry = null;
        String entryName$;
        while ((entry = zis.getNextEntry()) != null) {
            entryName$ = entry.getName();
            if (entryName$.equals(Entigrator.PROPERTY_INDEX)) {
                zis.close();
                return true;
            }
        }
        zis.close();
        return false;
    } catch (Exception e) {
        Logger.getLogger(ArchiveHandler.class.getName()).severe(e.toString());
        return false;
    }
}

From source file:gdt.data.entity.ArchiveHandler.java

private static boolean hasEntitiesDirInZipStream(ZipInputStream zis) {
    try {//from  ww w  . j  a v a  2  s.co  m
        ZipEntry entry = null;
        String entryName$;
        while ((entry = zis.getNextEntry()) != null) {
            entryName$ = entry.getName();
            if (entryName$.startsWith(Entigrator.ENTITY_BASE)) {
                zis.close();
                return true;
            }
        }
        zis.close();
        return false;
    } catch (Exception e) {
        Logger.getLogger(ArchiveHandler.class.getName()).severe(e.toString());
        return false;
    }
}

From source file:com.github.promeg.configchecker.Main.java

/**
 * Tries to open an input file as a Zip archive (jar/apk) with a
 * "classes.dex" inside.//  www  .  j  a v  a 2  s.  c  om
 */
void openInputFileAsZip(String fileName, List<String> dexFiles) throws IOException {
    ZipFile zipFile;

    // Try it as a zip file.
    try {
        zipFile = new ZipFile(fileName);
    } catch (FileNotFoundException fnfe) {
        // not found, no point in retrying as non-zip.
        System.err.println("Unable to open '" + fileName + "': " + fnfe.getMessage());
        throw fnfe;
    } catch (ZipException ze) {
        // not a zip
        return;
    }

    // Open and add all files matching "classes.*\.dex" in the zip file.
    for (ZipEntry entry : Collections.list(zipFile.entries())) {
        if (entry.getName().matches("classes.*\\.dex")) {
            dexFiles.add(openDexFile(zipFile, entry).getAbsolutePath());
        }
    }

    zipFile.close();
}