Example usage for java.util.zip ZipInputStream getNextEntry

List of usage examples for java.util.zip ZipInputStream getNextEntry

Introduction

In this page you can find the example usage for java.util.zip ZipInputStream getNextEntry.

Prototype

public ZipEntry getNextEntry() throws IOException 

Source Link

Document

Reads the next ZIP file entry and positions the stream at the beginning of the entry data.

Usage

From source file:eu.optimis.ics.ImageCreationServiceREST.java

/**
 * Uncompresses the given zip file. Unfortunately, the files' permission is not
 * preserved, especially with regards to an executable file.
 * @param zipFile       the zip file// w  ww .ja va  2s .  co m
 * @param destination   the directory location
 * @throws IOException  IO Exception
 */
private void unzipFile(File zipFile, String destination) throws IOException {
    LOGGER.debug("ics.REST.unzipFile(): Unzipping " + zipFile + " to directory " + destination);
    //LOGGER.debug("ics.REST.unzipFile(): Opening input streams");
    FileInputStream fis = new FileInputStream(zipFile);
    ZipInputStream zin = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;
    File destinationDirectory = new File(destination);

    while ((entry = zin.getNextEntry()) != null) {
        //LOGGER.debug("ics.REST.unzipFile(): Extracting: " + entry);

        if (entry.isDirectory()) {
            //LOGGER.debug("ics.REST.unzipFile(): Directory found, will be created");
            File targetDirectory = new File(destinationDirectory, entry.getName());
            targetDirectory.mkdir();
        } else {
            // extract data
            // open output streams
            int BUFFER = 2048;

            File destinationFile = new File(destinationDirectory, entry.getName());
            destinationFile.getParentFile().mkdirs();

            //LOGGER.debug("ics.REST.unzipFile(): Creating parent file of destination: "
            //        + destinationFile.getParent());
            //boolean parentDirectoriesCreated = destinationFile.getParentFile().mkdirs();                
            //LOGGER.debug("ics.REST.unzipFile(): Result of creating parents: "
            //        + parentDirectoriesCreated);

            FileOutputStream fos = new FileOutputStream(destinationFile);
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);

            int count;
            byte data[] = new byte[BUFFER];

            dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zin.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
        }
    }

    LOGGER.debug("ics.REST.unzipFile(): Unzipping file is done");
    zin.close();
    fis.close();
}

From source file:com.webpagebytes.cms.controllers.FlatStorageImporterExporter.java

public void importFromZipStep1(InputStream is) throws WPBIOException {
    ZipInputStream zis = new ZipInputStream(is);
    // we need to stop the notifications during import
    dataStorage.stopNotifications();/*from   w  w  w.jav a 2 s . c o  m*/
    try {
        ZipEntry ze = null;
        while ((ze = zis.getNextEntry()) != null) {
            String name = ze.getName();
            if (name.indexOf(PATH_URIS) >= 0) {
                if (name.indexOf("/parameters/") >= 0 && name.indexOf("metadata.xml") >= 0) {
                    importParameter(zis);
                } else if (name.indexOf("metadata.xml") >= 0) {
                    // this is a web site url
                    importUri(zis);
                }
            } else if (name.indexOf(PATH_GLOBALS) >= 0) {
                if (name.indexOf("metadata.xml") >= 0) {
                    importParameter(zis);
                }
            } else if (name.indexOf(PATH_SITE_PAGES) >= 0) {
                if (name.indexOf("/parameters/") >= 0 && name.indexOf("metadata.xml") >= 0) {
                    importParameter(zis);
                } else if (name.indexOf("metadata.xml") >= 0) {
                    importWebPage(zis);
                }
            } else if (name.indexOf(PATH_SITE_PAGES_MODULES) >= 0) {
                if (name.indexOf("metadata.xml") >= 0) {
                    importPageModule(zis);
                }
            } else if (name.indexOf(PATH_ARTICLES) >= 0) {
                if (name.indexOf("metadata.xml") >= 0) {
                    importArticle(zis);
                }
            } else if (name.indexOf(PATH_MESSAGES) >= 0) {
                if (name.indexOf("metadata.xml") >= 0) {
                    importMessage(zis);
                }
            } else if (name.indexOf(PATH_FILES) >= 0) {
                if (name.indexOf("metadata.xml") >= 0) {
                    importFile(zis);
                }
            } else if (name.indexOf(PATH_LOCALES) >= 0) {
                if (name.indexOf("metadata.xml") >= 0) {
                    importProject(zis);
                }
            }
            zis.closeEntry();
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getMessage(), e);
        throw new WPBIOException("cannot import from  zip step 1", e);
    }
}

From source file:eu.esdihumboldt.hale.io.appschema.writer.AppSchemaFileWriterTest.java

private void checkArchive(File archive) throws IOException {
    final File tempFile = File.createTempFile(Long.toString(System.currentTimeMillis()), ".xml");
    ZipInputStream zis = null;
    Document doc = null;//from ww w .  j a v a  2  s .  co m
    try {
        zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(archive)));

        ZipEntry lcvWsDir = zis.getNextEntry();
        checkDirEntry(lcvWsDir, "lcv/");
        zis.closeEntry();

        ZipEntry lcvWsFile = zis.getNextEntry();
        checkFileEntry(lcvWsFile, "lcv/" + AppSchemaIO.WORKSPACE_FILE);
        doc = readDocument(zis);
        checkWorkspaceDocument(doc, "lcv_workspace", "lcv");
        zis.closeEntry();

        ZipEntry lcvNsFile = zis.getNextEntry();
        checkFileEntry(lcvNsFile, "lcv/" + AppSchemaIO.NAMESPACE_FILE);
        doc = readDocument(zis);
        checkNamespaceDocument(doc, "lcv_namespace", "lcv", "http://inspire.ec.europa.eu/schemas/lcv/3.0");
        zis.closeEntry();

        ZipEntry lcvDataStoreDir = zis.getNextEntry();
        checkDirEntry(lcvDataStoreDir, "lcv/LandCoverVector/");
        zis.closeEntry();

        ZipEntry lcvDataStoreFile = zis.getNextEntry();
        checkFileEntry(lcvDataStoreFile, "lcv/LandCoverVector/" + AppSchemaIO.DATASTORE_FILE);
        doc = readDocument(zis);
        assertNotNull(doc);
        assertEquals("LandCoverVector_datastore",
                getFirstElementByTagName(doc.getDocumentElement(), "id").getTextContent());
        assertEquals("LandCoverVector",
                getFirstElementByTagName(doc.getDocumentElement(), "name").getTextContent());
        Element wsEl = getFirstElementByTagName(doc.getDocumentElement(), "workspace");
        assertNotNull(wsEl);
        assertEquals("lcv_workspace", getFirstElementByTagName(wsEl, "id").getTextContent());
        NodeList paramEntries = doc.getDocumentElement().getElementsByTagName("entry");
        assertNotNull(paramEntries);
        assertEquals(3, paramEntries.getLength());
        for (int i = 0; i < paramEntries.getLength(); i++) {
            Node param = paramEntries.item(i);
            Node key = param.getAttributes().getNamedItem("key");
            if ("dbtype".equals(key.getTextContent())) {
                assertEquals("app-schema", param.getTextContent());
            } else if ("namespace".equals(key.getTextContent())) {
                assertEquals("http://inspire.ec.europa.eu/schemas/lcv/3.0", param.getTextContent());
            } else if ("url".equals(key.getTextContent())) {
                assertEquals("file:./workspaces/lcv/LandCoverVector/LandCoverVector.xml",
                        param.getTextContent());
            } else {
                fail("Unknown connection parameter found: " + key.getTextContent());
            }
        }
        zis.closeEntry();

        ZipEntry mappingFile = zis.getNextEntry();
        checkFileEntry(mappingFile, "lcv/LandCoverVector/LandCoverVector.xml");
        ByteStreams.copy(zis, new FileOutputStream(tempFile));
        assertTrue(isMappingValid(tempFile));
        zis.closeEntry();

        ZipEntry unitFtDir = zis.getNextEntry();
        checkDirEntry(unitFtDir, "lcv/LandCoverVector/LandCoverUnit/");
        zis.closeEntry();

        ZipEntry unitFtFile = zis.getNextEntry();
        checkFileEntry(unitFtFile, "lcv/LandCoverVector/LandCoverUnit/" + AppSchemaIO.FEATURETYPE_FILE);
        doc = readDocument(zis);
        checkFeatureTypeDocument(doc, "LandCoverUnit");
        zis.closeEntry();

        ZipEntry unitLayerFile = zis.getNextEntry();
        checkFileEntry(unitLayerFile, "lcv/LandCoverVector/LandCoverUnit/" + AppSchemaIO.LAYER_FILE);
        doc = readDocument(zis);
        checkLayerDocument(doc, "LandCoverUnit");
        zis.closeEntry();

        ZipEntry datasetFtDir = zis.getNextEntry();
        checkDirEntry(datasetFtDir, "lcv/LandCoverVector/LandCoverDataset/");
        zis.closeEntry();

        ZipEntry datasetFtFile = zis.getNextEntry();
        checkFileEntry(datasetFtFile, "lcv/LandCoverVector/LandCoverDataset/" + AppSchemaIO.FEATURETYPE_FILE);
        doc = readDocument(zis);
        checkFeatureTypeDocument(doc, "LandCoverDataset");
        zis.closeEntry();

        ZipEntry datasetLayerFile = zis.getNextEntry();
        checkFileEntry(datasetLayerFile, "lcv/LandCoverVector/LandCoverDataset/" + AppSchemaIO.LAYER_FILE);
        doc = readDocument(zis);
        checkLayerDocument(doc, "LandCoverDataset");
        zis.closeEntry();

        ZipEntry baseWsDir = zis.getNextEntry();
        checkDirEntry(baseWsDir, "base/");
        zis.closeEntry();

        ZipEntry baseWsFile = zis.getNextEntry();
        checkFileEntry(baseWsFile, "base/" + AppSchemaIO.WORKSPACE_FILE);
        doc = readDocument(zis);
        checkWorkspaceDocument(doc, "base_workspace", "base");
        zis.closeEntry();

        ZipEntry baseNsFile = zis.getNextEntry();
        checkFileEntry(baseNsFile, "base/" + AppSchemaIO.NAMESPACE_FILE);
        doc = readDocument(zis);
        checkNamespaceDocument(doc, "base_namespace", "base", "http://inspire.ec.europa.eu/schemas/base/3.3");
        zis.closeEntry();

        ZipEntry gmlWsDir = zis.getNextEntry();
        checkDirEntry(gmlWsDir, "gml/");
        zis.closeEntry();

        ZipEntry gmlWsFile = zis.getNextEntry();
        checkFileEntry(gmlWsFile, "gml/" + AppSchemaIO.WORKSPACE_FILE);
        doc = readDocument(zis);
        checkWorkspaceDocument(doc, "gml_workspace", "gml");
        zis.closeEntry();

        ZipEntry gmlNsFile = zis.getNextEntry();
        checkFileEntry(gmlNsFile, "gml/" + AppSchemaIO.NAMESPACE_FILE);
        doc = readDocument(zis);
        checkNamespaceDocument(doc, "gml_namespace", "gml", "http://www.opengis.net/gml/3.2");
        zis.closeEntry();

        ZipEntry xlinkWsDir = zis.getNextEntry();
        checkDirEntry(xlinkWsDir, "xlink/");
        zis.closeEntry();

        ZipEntry xlinkWsFile = zis.getNextEntry();
        checkFileEntry(xlinkWsFile, "xlink/" + AppSchemaIO.WORKSPACE_FILE);
        doc = readDocument(zis);
        checkWorkspaceDocument(doc, "xlink_workspace", "xlink");
        zis.closeEntry();

        ZipEntry xlinkNsFile = zis.getNextEntry();
        checkFileEntry(xlinkNsFile, "xlink/" + AppSchemaIO.NAMESPACE_FILE);
        doc = readDocument(zis);
        checkNamespaceDocument(doc, "xlink_namespace", "xlink", "http://www.w3.org/1999/xlink");
        zis.closeEntry();

        ZipEntry xsiWsDir = zis.getNextEntry();
        checkDirEntry(xsiWsDir, "xsi/");
        zis.closeEntry();

        ZipEntry xsiWsFile = zis.getNextEntry();
        checkFileEntry(xsiWsFile, "xsi/" + AppSchemaIO.WORKSPACE_FILE);
        doc = readDocument(zis);
        checkWorkspaceDocument(doc, "xsi_workspace", "xsi");
        zis.closeEntry();

        ZipEntry xsiNsFile = zis.getNextEntry();
        checkFileEntry(xsiNsFile, "xsi/" + AppSchemaIO.NAMESPACE_FILE);
        doc = readDocument(zis);
        checkNamespaceDocument(doc, "xsi_namespace", "xsi", AppSchemaMappingUtils.XSI_URI);
        zis.closeEntry();

        assertNull(zis.getNextEntry());
    } catch (ZipException e) {
        fail("Exception reading generated ZIP archive: " + e.getMessage());
    } finally {
        if (tempFile != null)
            tempFile.delete();
        if (zis != null)
            zis.close();
    }
}

From source file:dpfmanager.shell.modules.report.core.ReportGenerator.java

/**
 * Read the file of the path./*from   w  w w  . j a v  a 2  s  . c o m*/
 *
 * @param pathStr the file path to read.
 * @return the content of the file in path
 */
public String readFile(String pathStr) {
    String text = "";
    String name = pathStr.substring(pathStr.lastIndexOf("/") + 1, pathStr.length());
    Path path = Paths.get(pathStr);
    try {
        if (Files.exists(path)) {
            // Look in current dir
            BufferedReader br = new BufferedReader(new FileReader(pathStr));
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            text = sb.toString();
            br.close();
        } else {
            // Look in JAR
            CodeSource src = ReportGenerator.class.getProtectionDomain().getCodeSource();
            if (src != null) {
                URL jar = src.getLocation();
                ZipInputStream zip;

                zip = new ZipInputStream(jar.openStream());
                ZipEntry zipFile;
                boolean found = false;
                while ((zipFile = zip.getNextEntry()) != null && !found) {
                    if (zipFile.getName().endsWith(name)) {
                        BufferedReader br = new BufferedReader(new InputStreamReader(zip));
                        String line = br.readLine();
                        while (line != null) {
                            text += line + System.lineSeparator();
                            line = br.readLine();
                        }
                        found = true;
                    }
                    zip.closeEntry();
                }
            }
        }
    } catch (FileNotFoundException e) {
        context.send(BasicConfig.MODULE_MESSAGE,
                new LogMessage(getClass(), Level.ERROR, "Template for html not found in dir."));
    } catch (IOException e) {
        context.send(BasicConfig.MODULE_MESSAGE,
                new LogMessage(getClass(), Level.ERROR, "Error reading " + pathStr));
    }

    return text;
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureVerifier.java

private CTTypes getContentTypes(URL url)
        throws IOException, ParserConfigurationException, SAXException, JAXBException {
    ZipInputStream zipInputStream = new ZipInputStream(url.openStream());
    ZipEntry zipEntry;// ww w.j  a  v  a  2  s.  c o  m
    InputStream contentTypesInputStream = null;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (!"[Content_Types].xml".equals(zipEntry.getName())) {
            continue;
        }
        contentTypesInputStream = zipInputStream;
        break;
    }
    if (null == contentTypesInputStream) {
        return null;
    }
    JAXBContext jaxbContext = JAXBContext
            .newInstance(be.fedict.eid.applet.service.signer.jaxb.opc.contenttypes.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<CTTypes> contentTypesElement = (JAXBElement<CTTypes>) unmarshaller
            .unmarshal(contentTypesInputStream);
    return contentTypesElement.getValue();
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureVerifier.java

private CTRelationships getRelationships(URL url, String relationshipsEntryName)
        throws IOException, JAXBException {
    ZipInputStream zipInputStream = new ZipInputStream(url.openStream());
    ZipEntry zipEntry;// w w  w.  j av  a2  s . c om
    InputStream relationshipsInputStream = null;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (false == relationshipsEntryName.equals(zipEntry.getName())) {
            continue;
        }
        relationshipsInputStream = zipInputStream;
        break;
    }
    if (null == relationshipsInputStream) {
        return null;
    }
    JAXBContext jaxbContext = JAXBContext
            .newInstance(be.fedict.eid.applet.service.signer.jaxb.opc.relationships.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<CTRelationships> relationshipsElement = (JAXBElement<CTRelationships>) unmarshaller
            .unmarshal(relationshipsInputStream);
    return relationshipsElement.getValue();
}

From source file:com.taobao.android.builder.tools.sign.LocalSignedJarBuilder.java

/**
 * Copies the content of a Jar/Zip archive into the receiver archive.
 * <p/>An optional {@link IZipEntryFilter} allows to selectively choose which files
 * to copy over./*  w ww  .j a  v a2 s . co  m*/
 *
 * @param input  the {@link InputStream} for the Jar/Zip to copy.
 * @param filter the filter or <code>null</code>
 * @throws IOException
 * @throws SignedJarBuilder.IZipEntryFilter.ZipAbortException if the {@link IZipEntryFilter} filter indicated that the write
 *                                                            must be aborted.
 */
public void writeZip(InputStream input, IZipEntryFilter filter)
        throws IOException, IZipEntryFilter.ZipAbortException {
    ZipInputStream zis = new ZipInputStream(input);

    try {
        // loop on the entries of the intermediary package and put them in the final package.
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();

            // do not take directories or anything inside a potential META-INF folder.
            if (entry.isDirectory()) {
                continue;
            }

            // ignore some of the content in META-INF/ but not all
            if (name.startsWith("META-INF/")) {
                // ignore the manifest file.
                String subName = name.substring(9);
                if ("MANIFEST.MF".equals(subName)) {
                    int count;
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    while ((count = zis.read(buffer)) != -1) {
                        out.write(buffer, 0, count);
                    }
                    ByteArrayInputStream swapStream = new ByteArrayInputStream(out.toByteArray());
                    Manifest manifest = new Manifest(swapStream);
                    mManifest.getMainAttributes().putAll(manifest.getMainAttributes());
                    continue;
                }

                // special case for Maven meta-data because we really don't care about them in apks.
                if (name.startsWith("META-INF/maven/")) {
                    continue;
                }

                // check for subfolder
                int index = subName.indexOf('/');
                if (index == -1) {
                    // no sub folder, ignores signature files.
                    if (subName.endsWith(".SF") || name.endsWith(".RSA") || name.endsWith(".DSA")) {
                        continue;
                    }
                }
            }

            // if we have a filter, we check the entry against it
            if (filter != null && !filter.checkEntry(name)) {
                continue;
            }

            JarEntry newEntry;

            // Preserve the STORED method of the input entry.
            if (entry.getMethod() == JarEntry.STORED) {
                newEntry = new JarEntry(entry);
            } else {
                // Create a new entry so that the compressed len is recomputed.
                newEntry = new JarEntry(name);
            }

            writeEntry(zis, newEntry);

            zis.closeEntry();
        }
    } finally {
        zis.close();
    }
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureVerifier.java

@SuppressWarnings("unchecked")
public List<String> getSignatureResourceNames(byte[] document) throws IOException, JAXBException {
    List<String> signatureResourceNames = new LinkedList<String>();
    ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(document));
    ZipEntry zipEntry;/* ww  w  .  j av  a 2s  .  com*/
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if ("_rels/.rels".equals(zipEntry.getName())) {
            break;
        }
    }
    if (null == zipEntry) {
        LOG.debug("no _rels/.rels relationship part present");
        return signatureResourceNames;
    }

    String dsOriginPart = null;
    JAXBElement<CTRelationships> packageRelationshipsElement = (JAXBElement<CTRelationships>) this.relationshipsUnmarshaller
            .unmarshal(zipInputStream);
    CTRelationships packageRelationships = packageRelationshipsElement.getValue();
    List<CTRelationship> packageRelationshipList = packageRelationships.getRelationship();
    for (CTRelationship packageRelationship : packageRelationshipList) {
        if (DIGITAL_SIGNATURE_ORIGIN_REL_TYPE.equals(packageRelationship.getType())) {
            dsOriginPart = packageRelationship.getTarget();
            break;
        }
    }
    if (null == dsOriginPart) {
        LOG.debug("no Digital Signature Origin part present");
        return signatureResourceNames;
    }
    LOG.debug("Digital Signature Origin part: " + dsOriginPart);
    String dsOriginName = dsOriginPart.substring(dsOriginPart.lastIndexOf("/") + 1);
    LOG.debug("Digital Signature Origin base: " + dsOriginName);
    String dsOriginSegment = dsOriginPart.substring(0, dsOriginPart.lastIndexOf("/")) + "/";
    LOG.debug("Digital Signature Origin segment: " + dsOriginSegment);
    String dsOriginRels = dsOriginSegment + "_rels/" + dsOriginName + ".rels";
    LOG.debug("Digital Signature Origin relationship part: " + dsOriginRels);

    zipInputStream = new ZipInputStream(new ByteArrayInputStream(document));
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (dsOriginRels.equals(zipEntry.getName())) {
            break;
        }
    }
    if (null == zipEntry) {
        LOG.debug("no Digital Signature Origin relationship part present");
        return signatureResourceNames;
    }

    JAXBElement<CTRelationships> dsoRelationshipsElement = (JAXBElement<CTRelationships>) this.relationshipsUnmarshaller
            .unmarshal(zipInputStream);
    CTRelationships dsoRelationships = dsoRelationshipsElement.getValue();
    List<CTRelationship> dsoRelationshipList = dsoRelationships.getRelationship();
    for (CTRelationship dsoRelationship : dsoRelationshipList) {
        if (DIGITAL_SIGNATURE_REL_TYPE.equals(dsoRelationship.getType())) {
            String signatureResourceName = dsOriginSegment + dsoRelationship.getTarget();
            signatureResourceNames.add(signatureResourceName);
        }
    }

    return signatureResourceNames;
}

From source file:eu.europa.esig.dss.asic.validation.ASiCContainerValidator.java

private void analyseEntries() throws DSSException {

    ZipInputStream asicsInputStream = null;
    try {/* ww  w . j  av a  2  s.c o  m*/

        MimeType asicEntryMimeType = null;
        asicsInputStream = new ZipInputStream(asicContainer.openStream()); // The underlying stream is closed by the parent (asicsInputStream).

        for (ZipEntry entry = asicsInputStream.getNextEntry(); entry != null; entry = asicsInputStream
                .getNextEntry()) {

            String entryName = entry.getName();
            if (isCAdES(entryName)) {

                if (xadesSigned) {
                    throw new DSSNotETSICompliantException(
                            DSSNotETSICompliantException.MSG.DIFFERENT_SIGNATURE_FORMATS);
                }
                addEntryElement(entryName, signatures, asicsInputStream);
                cadesSigned = true;
            } else if (isXAdES(entryName)) {

                if (cadesSigned) {
                    throw new DSSNotETSICompliantException(
                            DSSNotETSICompliantException.MSG.DIFFERENT_SIGNATURE_FORMATS);
                }
                addEntryElement(entryName, signatures, asicsInputStream);
                xadesSigned = true;
            } else if (isTimestamp(entryName)) {

                addEntryElement(entryName, signatures, asicsInputStream);
                timestamped = true;
            } else if (isASiCManifest(entryName)) {

                addAsicManifestEntryElement(entryName, detachedContents, asicsInputStream);
            } else if (isManifest(entryName)) {

                addEntryElement(entryName, detachedContents, asicsInputStream);
            } else if (isContainer(entryName)) {

                addEntryElement(entryName, detachedContents, asicsInputStream);
            } else if (isMetadata(entryName)) {

                addEntryElement(entryName, detachedContents, asicsInputStream);
            } else if (isMimetype(entryName)) {

                final DSSDocument mimeType = addEntryElement(entryName, detachedContents, asicsInputStream);
                asicEntryMimeType = getMimeType(mimeType);
            } else if (entryName.indexOf("/") == -1) {

                addEntryElement(entryName, detachedContents, asicsInputStream);
            } else if (entryName.endsWith("/")) { // Folder
                continue;
            } else {

                addEntryElement(entryName, detachedContents, asicsInputStream);
            }
        }
        asicMimeType = determinateAsicMimeType(asicContainer.getMimeType(), asicEntryMimeType);
        if (MimeType.ASICS == asicMimeType) {

            final ListIterator<DSSDocument> dssDocumentListIterator = detachedContents.listIterator();
            while (dssDocumentListIterator.hasNext()) {

                final DSSDocument dssDocument = dssDocumentListIterator.next();
                final String detachedContentName = dssDocument.getName();
                if ("mimetype".equals(detachedContentName)) {
                    dssDocumentListIterator.remove();
                } else if (detachedContentName.indexOf('/') != -1) {
                    dssDocumentListIterator.remove();
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof DSSException) {
            throw (DSSException) e;
        }
        throw new DSSException(e);
    } finally {
        IOUtils.closeQuietly(asicsInputStream);
    }
}