Example usage for java.util.zip ZipEntry toString

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the ZIP entry.

Usage

From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ProjectPage.java

private void actionImportProject(List<FileUpload> exportedProjects, boolean aGenerateUsers) {
    Project importedProject = new Project();
    // import multiple projects!
    for (FileUpload exportedProject : exportedProjects) {
        InputStream tagInputStream;
        try {/*from w  ww. j av  a  2s .  co m*/
            tagInputStream = exportedProject.getInputStream();
            if (!ZipUtils.isZipStream(tagInputStream)) {
                error("Invalid ZIP file");
                return;
            }
            File zipFfile = exportedProject.writeToTempFile();
            if (!ImportUtil.isZipValidWebanno(zipFfile)) {
                error("Incompatible to webanno ZIP file");
            }
            ZipFile zip = new ZipFile(zipFfile);
            InputStream projectInputStream = null;
            for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements();) {
                ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
                if (entry.toString().replace("/", "").startsWith(ImportUtil.EXPORTED_PROJECT)
                        && entry.toString().replace("/", "").endsWith(".json")) {
                    projectInputStream = zip.getInputStream(entry);
                    break;
                }
            }

            // projectInputStream =
            // uploadedFile.getInputStream();
            String text = IOUtils.toString(projectInputStream, "UTF-8");
            de.tudarmstadt.ukp.clarin.webanno.model.export.Project importedProjectSetting = JSONUtil
                    .getJsonConverter().getObjectMapper()
                    .readValue(text, de.tudarmstadt.ukp.clarin.webanno.model.export.Project.class);

            importedProject = ImportUtil.createProject(importedProjectSetting, repository, userRepository);

            Map<de.tudarmstadt.ukp.clarin.webanno.model.export.AnnotationFeature, AnnotationFeature> featuresMap = ImportUtil
                    .createLayer(importedProject, importedProjectSetting, userRepository, annotationService);
            ImportUtil.createSourceDocument(importedProjectSetting, importedProject, repository, userRepository,
                    featuresMap);
            ImportUtil.createMiraTemplate(importedProjectSetting, automationService, featuresMap);
            ImportUtil.createCrowdJob(importedProjectSetting, repository, importedProject);

            ImportUtil.createAnnotationDocument(importedProjectSetting, importedProject, repository);
            ImportUtil.createProjectPermission(importedProjectSetting, importedProject, repository,
                    aGenerateUsers, userRepository);
            /*
             * for (TagSet tagset : importedProjectSetting.getTagSets()) {
             * ImportUtil.createTagset(importedProject, tagset, projectRepository,
             * annotationService); }
             */
            // add source document content
            ImportUtil.createSourceDocumentContent(zip, importedProject, repository);
            // add annotation document content
            ImportUtil.createAnnotationDocumentContent(zip, importedProject, repository);
            // create curation document content
            ImportUtil.createCurationDocumentContent(zip, importedProject, repository);
            // create project log
            ImportUtil.createProjectLog(zip, importedProject, repository);
            // create project guideline
            ImportUtil.createProjectGuideline(zip, importedProject, repository);
            // cretae project META-INF
            ImportUtil.createProjectMetaInf(zip, importedProject, repository);
        } catch (IOException e) {
            error("Error Importing Project " + ExceptionUtils.getRootCauseMessage(e));
        }
    }
    projectDetailForm.setModelObject(importedProject);
    SelectionModel selectedProjectModel = new SelectionModel();
    selectedProjectModel.project = importedProject;
    projectSelectionForm.setModelObject(selectedProjectModel);
    projectDetailForm.setVisible(true);
    RequestCycle.get().setResponsePage(getPage());
}

From source file:org.esa.snap.engine_utilities.util.ZipUtils.java

public static String getRootFolder(final File file, final String headerFileName) throws IOException {
    final ZipFile productZip = new ZipFile(file, ZipFile.OPEN_READ);

    final Optional result = productZip.stream().filter(ze -> !ze.isDirectory())
            .filter(ze -> ze.getName().toLowerCase().endsWith(headerFileName)).findFirst();
    if (result.isPresent()) {
        ZipEntry ze = (ZipEntry) result.get();
        String path = ze.toString();
        int sepIndex = path.lastIndexOf('/');
        if (sepIndex > 0) {
            return path.substring(0, sepIndex) + '/';
        } else {//from  w  w w.j a  v  a  2s .  com
            return "";
        }
    }
    return "";
}

From source file:org.esa.snap.util.ZipUtils.java

public static String getRootFolder(final File file, final String headerFileName) throws IOException {
    final ZipFile productZip = new ZipFile(file, ZipFile.OPEN_READ);

    final Optional result = productZip.stream().filter(ze -> !ze.isDirectory())
            .filter(ze -> ze.getName().toLowerCase().endsWith(headerFileName)).findFirst();
    ZipEntry ze = (ZipEntry) result.get();
    String path = ze.toString();
    int sepIndex = path.lastIndexOf('/');
    if (sepIndex > 0) {
        return path.substring(0, sepIndex) + '/';
    } else {//from ww  w  . j a v a 2s .c om
        return "";
    }
}

From source file:org.jboss.windup.decorator.archive.ZipDecorator.java

@Override
public void processMeta(ZipMetadata archive) {
    try {//from  w  ww.  ja  v a  2s.  c  om

        ZipEntry entry;
        List<Interrogator<?>> loadedInterrogators = null;
        // first, check to see whether the archive is a known vendor archive. this will allow us to only process version information and skip all other files.
        if (knownArchiveProfiler.isExclusivelyKnownArchive(archive)) {
            // only check for version information.
            loadedInterrogators = versionInterrogators;
        } else {
            loadedInterrogators = interrogators;
        }

        // first, check all entries against the known vendors list.
        Enumeration<?> e = archive.getZipFile().entries();
        while (e.hasMoreElements()) {
            entry = (ZipEntry) e.nextElement();

            // create the archive entry meta file.
            ZipEntryMetadata archiveEntry = new ZipEntryMetadata();
            archiveEntry.setArchiveMeta(archive);
            archiveEntry.setZipEntry(entry);

            for (Interrogator<?> interrogator : loadedInterrogators) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Entry: " + entry.toString() + " -> Interrogator: " + interrogator.getClass());
                }

                interrogator.processArchiveEntry(archiveEntry);
            }
        }
    } catch (Exception e) {
        if (e instanceof FatalWindupException) {
            throw (FatalWindupException) e;
        }

        LOG.error("Exception processing archive: " + archive.getName(), e);
    }
}

From source file:org.jboss.windup.metadata.type.ZipEntryMetadata.java

/**
 * Unzips a given ZipEntry to a base output direction.
 * /*from  w  ww. j  a  v a2  s  .c  o  m*/
 * @param entry
 *            ZipEntry to unzip
 * @param zipfile
 *            ZipFile to extract ZipEntry from
 * @param archiveOutputDirectory
 *            base directory to extract ZipEntry.
 * @return Unzipped file.
 * @throws IOException
 * @throws FileNotFoundException
 */
protected File unzipEntry(ZipEntry entry, ZipFile zipfile, File archiveOutputDirectory)
        throws IOException, FileNotFoundException {
    BufferedOutputStream dest;
    BufferedInputStream is;
    String pathOutput = null;
    if (StringUtils.contains(entry.toString(), "/")) {
        pathOutput = StringUtils.substringBeforeLast(entry.toString(), "/");
    } else {
        pathOutput = File.separator;
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("PathOutput: " + pathOutput);
        LOG.trace("PathEntry: " + entry);
        LOG.trace("ArchiveOutput: " + archiveOutputDirectory.getAbsolutePath());
    }

    File entryPathOutput = new File(archiveOutputDirectory.getAbsolutePath() + File.separator + pathOutput);
    File entryOutput = new File(archiveOutputDirectory.getAbsolutePath() + File.separator + entry);

    if (!entryOutput.exists()) {
        FileUtils.forceMkdir(entryPathOutput);
        is = new BufferedInputStream(zipfile.getInputStream(entry));
        LOG.debug("Unzipping: " + entryOutput.getAbsolutePath());

        int count;
        byte data[] = new byte[BUFFER];
        FileOutputStream fos = new FileOutputStream(entryOutput);
        dest = new BufferedOutputStream(fos, BUFFER);

        while ((count = is.read(data, 0, BUFFER)) != -1) {
            dest.write(data, 0, count);
        }

        dest.flush();
        dest.close();
        is.close();
    }

    return entryOutput;
}

From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java

protected File unzipEntry(ZipMetadata parent, ZipEntry entry, ZipFile zipfile, File archiveOutputDirectory) {
    BufferedOutputStream dest = null;
    BufferedInputStream is = null;
    String pathOutput = null;//from   w w w. j  a v  a 2s  . c om
    if (StringUtils.contains(entry.toString(), "/")) {
        pathOutput = StringUtils.substringBeforeLast(entry.toString(), "/");
    } else {
        pathOutput = File.separator;
    }
    File entryPathOutput = new File(
            archiveOutputDirectory.getAbsolutePath() + safeExtractKey + File.separator + pathOutput);
    File entryOutput = new File(
            archiveOutputDirectory.getAbsolutePath() + safeExtractKey + File.separator + entry);
    if (!entryOutput.exists()) {
        try {
            FileUtils.forceMkdir(entryPathOutput);
            is = new BufferedInputStream(zipfile.getInputStream(entry));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unzipping: " + entryOutput.getAbsolutePath());
            }

            int count;
            byte data[] = new byte[BUFFER];
            FileOutputStream fos = new FileOutputStream(entryOutput);
            dest = new BufferedOutputStream(fos, BUFFER);

            while ((count = is.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();

            return entryOutput;
        } catch (IOException e) {
            LOG.error(e);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(dest);
        }
    } else {
        LOG.warn("Entry: " + entry.toString() + " is a duplicate.  Returning the first entry.");
        return entryOutput;
    }

    return null;

}

From source file:org.zaproxy.zap.control.AddOnLoader.java

private List<ClassNameWrapper> getJarClassNames(ClassLoader cl, File file, String packageName) {
    List<ClassNameWrapper> classNames = new ArrayList<>();
    ZipEntry entry = null;
    String className = "";
    try (JarFile jarFile = new JarFile(file)) {
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
                continue;
            }/* www  .ja  v a2 s .  c  o  m*/
            className = entry.toString().replaceAll("\\.class$", "").replaceAll("/", ".");
            if (className.indexOf(packageName) >= 0) {
                classNames.add(new ClassNameWrapper(cl, className));
            }
        }
    } catch (Exception e) {
        logger.error("Failed to open file: " + file.getAbsolutePath(), e);
    }
    return classNames;
}

From source file:org.zaproxy.zap.control.AddOnLoader.java

private List<ClassNameWrapper> getJarClassNames(AddOn ao, String packageName) {
    List<ClassNameWrapper> classNames = new ArrayList<>();
    ZipEntry entry = null;
    String className = "";
    try (JarFile jarFile = new JarFile(ao.getFile())) {
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
                continue;
            }/*w w  w . j a  v  a2 s.com*/
            className = entry.toString().replaceAll("\\.class$", "").replaceAll("/", ".");
            if (className.indexOf(packageName) >= 0) {
                classNames.add(new ClassNameWrapper(this.addOnLoaders.get(ao.getId()), className));
            }
        }
    } catch (Exception e) {
        logger.error("Failed to open file: " + ao.getFile().getAbsolutePath(), e);
    }
    return classNames;
}