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:FeatureExtraction.FeatureExtractorOOXMLStructuralPathsInputStream.java

private void ExtractStructuralFeaturesInMemory(InputStream fileInputStream,
        Map<String, Integer> structuralPaths) {
    String path;/*from  ww  w . ja v a  2s.  c o  m*/
    String directoryPath;
    String fileExtension;
    try {
        File file = new File(fileInputStream.hashCode() + "");
        try (FileOutputStream fos = new FileOutputStream(file)) {
            IOUtils.copy(fileInputStream, fos);
        }

        ZipFile zipFile = new ZipFile(file);

        for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            path = entry.getName();
            directoryPath = FilenameUtils.getFullPath(path);
            fileExtension = FilenameUtils.getExtension(path);

            AddStructuralPath(directoryPath, structuralPaths);
            AddStructuralPath(path, structuralPaths);

            if (fileExtension.equals("rels") || fileExtension.equals("xml")) {
                AddXMLStructuralPaths(zipFile.getInputStream(entry), path, structuralPaths);
            }
        }
    } catch (IOException ex) {
        Console.PrintException(String.format("Error extracting OOXML structural features from file in memory"),
                ex);
    }
}

From source file:com.arrggh.eve.api.sde.StaticDataExportImporter.java

public void importFile(File zipFile) throws IOException {
    try (ZipFile sdeZip = new ZipFile(zipFile)) {
        Map<Long, Type> types = processMap("Types",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/typeIDs.yaml")), Types.TYPE_MAP);

        List<InventoryType> items = processArray("Items",
                sdeZip.getInputStream(sdeZip.getEntry("sde/bsd/invItems.yaml")), Types.INVENTORY_TYPE_ARRAY);

        Map<Long, Blueprint> blueprints = processMap("Blueprint",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/blueprints.yaml")), Types.BLUEPRINT_MAP);

        for (ZipEntry entry : Collections.list(sdeZip.entries())) {
            String entryName = entry.getName();
            if (entryName.contains("sde/fsd/universe") && entryName.endsWith(".staticdata")) {
                if (entryName.endsWith("constellation.staticdata")) {
                    Constellation constellation = process(sdeZip.getInputStream(entry),
                            Types.CONSTELLATION_TYPE);
                }/*from w  w w . j a  va 2s.co m*/
                if (entryName.endsWith("solarsystem.staticdata")) {
                    SolarSystem solarsystem = process(sdeZip.getInputStream(entry), Types.SOLARSYSTEM_TYPE);
                }
            }
        }

        Map<Long, Icon> icons = processMap("Icons",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/iconIDs.yaml")), Types.ICON_MAP);
        Map<Long, Graphic> graphics = processMap("Graphics",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/graphicIDs.yaml")), Types.GRAPHICS_MAP);
        Map<Long, Certificate> certificates = processMap("Certificates",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/certificates.yaml")), Types.CERTIFICATE_MAP);
        Map<Long, Group> groups = processMap("Groups",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/groupIDs.yaml")), Types.GROUPS_MAP);
        Map<Long, Category> categories = processMap("Categories",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/categoryIDs.yaml")), Types.CATEGORY_MAP);
        Map<Long, SkinLicense> skinLicenses = processMap("Skin Licenses",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/skinLicenses.yaml")), Types.SKIN_LICENCE_MAP);
        Map<Long, SkinMaterial> skinMaterials = processMap("Skin Materials",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/skinMaterials.yaml")), Types.SKIN_MATERIAL_MAP);
        Map<Long, Skin> skins = processMap("Skins",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/skins.yaml")), Types.SKIN_MAP);
        List<TournamentRuleSet> tournamentRuleSets = processArray("Tournament Rule Sets",
                sdeZip.getInputStream(sdeZip.getEntry("sde/fsd/tournamentRuleSets.yaml")),
                Types.TOURNAMENT_RULE_SET_ARRAY);
    }
}

From source file:com.thoughtworks.go.domain.DirHandler.java

private String getSrcFilePath(ZipEntry entry) {
    String parent = new File(srcFile).getParent();
    return FilenameUtils.separatorsToUnix(new File(parent, entry.getName()).getPath());
}

From source file:com.wso2mobile.mam.packageExtractor.ZipFileReading.java

public String readAndroidManifestFile(String filePath) {
    String xml = "";
    try {//from  w w w  .  ja  v a  2 s  .  c o  m
        ZipInputStream stream = new ZipInputStream(new FileInputStream(filePath));
        try {
            ZipEntry entry;
            while ((entry = stream.getNextEntry()) != null) {
                if (entry.getName().equals("AndroidManifest.xml")) {
                    StringBuilder builder = new StringBuilder();
                    xml = AndroidXMLParsing.decompressXML(IOUtils.toByteArray(stream));
                }
            }
        } finally {
            stream.close();
        }
        Document doc = loadXMLFromString(xml);
        doc.getDocumentElement().normalize();
        JSONObject obj = new JSONObject();
        obj.put("version", doc.getDocumentElement().getAttribute("versionName"));
        obj.put("package", doc.getDocumentElement().getAttribute("package"));
        xml = obj.toJSONString();
    } catch (Exception e) {
        xml = "Exception occured " + e;
    }
    return xml;
}

From source file:de.onyxbits.raccoon.ptools.ToolSupport.java

private void unzip(File file) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    try {//from www .  j  a  v  a2  s  . c  om
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            File entryDestination = new File(binDir, entry.getName());
            if (entry.isDirectory())
                entryDestination.mkdirs();
            else {
                entryDestination.getParentFile().mkdirs();
                InputStream in = zipFile.getInputStream(entry);
                OutputStream out = new FileOutputStream(entryDestination);
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(in);
                out.close();
            }
        }
    } finally {
        zipFile.close();
    }
}

From source file:org.cloudfoundry.client.lib.archive.AbstractApplicationArchiveTest.java

@Test
@Ignore//ww w. j  a va  2  s. c om
public void shouldAdaptEntries() throws Exception {
    Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
    while (zipEntries.hasMoreElements()) {
        ZipEntry zipEntry = zipEntries.nextElement();
        ApplicationArchive.Entry archiveEntry = archiveEntries.remove(zipEntry.getName());
        assertThat(archiveEntry, is(notNullValue()));
        assertThat(archiveEntry.getSize(), is(zipEntry.getSize()));
        assertThat(archiveEntry.isDirectory(), is(zipEntry.isDirectory()));
    }
    assertThat(archiveEntries.size(), is(0));
}

From source file:dk.deck.resolver.util.ZipUtils.java

private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {

    if (entry.isDirectory()) {
        createDir(new File(outputDir, entry.getName()));
        return;// www . ja va 2s  . c o m
    }

    File outputFile = new File(outputDir, entry.getName());
    if (!outputFile.getParentFile().exists()) {
        createDir(outputFile.getParentFile());
    }

    // log.debug("Extracting: " + entry);
    BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));

    try {
        IOUtils.copy(inputStream, outputStream);
    } finally {
        outputStream.close();
        inputStream.close();
    }
}

From source file:ZipTest.java

/**
 * Scans the contents of the ZIP archive and populates the combo box.
 *///from  ww w  . j a  v a2s. c  om
public void scanZipFile() {
    new SwingWorker<Void, String>() {
        protected Void doInBackground() throws Exception {
            ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname));
            ZipEntry entry;
            while ((entry = zin.getNextEntry()) != null) {
                publish(entry.getName());
                zin.closeEntry();
            }
            zin.close();
            return null;
        }

        protected void process(List<String> names) {
            for (String name : names)
                fileCombo.addItem(name);

        }
    }.execute();
}

From source file:de.knowwe.revisions.upload.UploadRevisionZip.java

@SuppressWarnings("unchecked")
@Override/* w w  w  .j  av a2 s  .  c o  m*/
public void execute(UserActionContext context) throws IOException {

    HashMap<String, String> pages = new HashMap<>();
    List<FileItem> items = null;
    String zipname = null;
    try {
        items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(context.getRequest());
    } catch (FileUploadException e) {
        throw new IOException("error during processing upload", e);
    }

    for (FileItem item : items) {
        zipname = item.getName();
        InputStream filecontent = item.getInputStream();

        ZipInputStream zin = new ZipInputStream(filecontent);
        ZipEntry ze;

        while ((ze = zin.getNextEntry()) != null) {
            String name = ze.getName();
            if (!name.contains("/")) {
                // this is an article
                String title = Strings.decodeURL(name);
                title = title.substring(0, title.length() - 4);
                String content = IOUtils.toString(zin, "UTF-8");
                zin.closeEntry();
                pages.put(title, content);
            } else {
                // TODO: what to do here?
                // this is an attachment
                // String[] splittedName = name.split("/");
                // String title = Strings.decodeURL(splittedName[0]);
                // String filename = Strings.decodeURL(splittedName[1]);
                //
                // System.out.println("Attachment: " + name);
                // String content = IOUtils.toString(zin, "UTF-8");
                // Environment.getInstance().getWikiConnector().storeAttachment(title,
                // filename,
                // context.getUserName(), zin);
                zin.closeEntry();
            }
        }
        zin.close();
        filecontent.close();
    }
    if (zipname != null) {
        UploadedRevision rev = new UploadedRevision(context.getWeb(), pages, zipname);
        RevisionManager.getRM(context).setUploadedRevision(rev);
    }
    context.sendRedirect("../Wiki.jsp?page=" + context.getTitle());

}

From source file:org.openmrs.module.clinicalsummary.io.UploadSummariesTask.java

/**
 * In order to correctly perform the encryption - decryption process, user must store their init vector table. This init vector will be given to the
 * user as a small file and it is required to perform the decryption process.
 *
 * @throws Exception/* w  w w  .j  a  v  a 2s. c om*/
 */
protected void processInitVector() throws Exception {
    String encryptedFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_ENCRYPTED),
            ".");
    ZipFile encryptedFile = new ZipFile(new File(TaskUtils.getEncryptedOutputPath(), encryptedFilename));

    Enumeration<? extends ZipEntry> entries = encryptedFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry zipEntry = entries.nextElement();
        if (zipEntry.getName().endsWith(TaskConstants.FILE_TYPE_SECRET)) {
            InputStream inputStream = encryptedFile.getInputStream(zipEntry);
            initVector = FileCopyUtils.copyToByteArray(inputStream);
            if (initVector.length != IV_SIZE) {
                throw new Exception("Secret file is corrupted or invalid secret file are being used.");
            }
        }
    }
}