Examples of ArchiveEntry


Examples of org.albite.util.archive.ArchiveEntry

        final String opfFilePath;

        /*
         * first load META-INF/container.xml
         */
        ArchiveEntry container =
                bookArchive.getEntry("META-INF/container.xml");

        if (container == null) {
            throw new BookException("Missing manifest");
        }

        in = container.openInputStream();

        try {
            KXmlParser parser = null;
            Document doc = null;
            Element root;
            Element kid;
            try {
                parser = new KXmlParser();
                parser.setInput(new AlbiteStreamReader(
                        in, Encodings.DEFAULT));

                doc = new Document();
                doc.parse(parser);
                parser = null;

                root = doc.getRootElement();

                Element rfile = root
                        .getElement(KXmlParser.NO_NAMESPACE, "rootfiles")
                        .getElement(KXmlParser.NO_NAMESPACE, "rootfile");

                opfFileName = rfile.getAttributeValue(
                        KXmlParser.NO_NAMESPACE, "full-path");

                if (opfFileName == null) {
                    throw new BookException("Missing opf file");
                }

                opfFilePath = RandomReadingFile.getPathFromURL(opfFileName);

                //#debug
                AlbiteMIDlet.LOGGER.log(opfFilePath);

            } catch (XmlPullParserException xppe) {
                parser = null;
                doc = null;
                throw new BookException(
                    "container.xml is invalid");
            }
        } finally {
            in.close();
        }

        /*
         * now the opf file
         */
        ArchiveEntry opfFile = bookArchive.getEntry(opfFileName);

        if (opfFile == null) {
            throw new BookException("Missing opf");
        }

        in = opfFile.openInputStream();

        try {
            KXmlParser parser = null;
            Document doc = null;
            Element root;
            Element kid;

            try {
                parser = new KXmlParser();

                try {
                    parser.setFeature(
                            KXmlParser.FEATURE_PROCESS_NAMESPACES, true);
                } catch (XmlPullParserException e) {}

                parser.setInput(new AlbiteStreamReader(
                        in, Encodings.DEFAULT));

                doc = new Document();
                doc.parse(parser);
                parser = null;

                root = doc.getRootElement();

                try {
                    /*
                     * try to get the metadata
                     */
//                    meta = new Hashtable(10);

                    Element metadata = getElement(root, "metadata");
                   
                    Element dcmetadata = getElement(metadata, "dc-metadata");
                   
                    if (dcmetadata != null) {
                        metadata = dcmetadata;
                    }

                    if (metadata != null) {
                        for (int i = 0; i < metadata.getChildCount(); i++) {
                            if (metadata.getType(i) != Node.ELEMENT) {
                                continue;
                            }

                            kid = metadata.getElement(i);

                            if (kid.getName().equalsIgnoreCase("title")) {
                                title = text(kid);
                                continue;
                            }

                            if (kid.getName().equalsIgnoreCase("creator")) {
                                author = text(kid);
                                continue;
                            }

                            if (kid.getName().equalsIgnoreCase("language")) {
                                language = text(kid);
                                /*
                                 * squash it to a 2-letter tag
                                 */
                                if (language.length() > 2) {
                                    language = language.substring(0, 2);
                                }

                                /*
                                 * set currentLanguage to the default value
                                 * afterward (in loadUserFile) it will
                                 * be overwritten
                                 */
                                currentLanguage = language;

                                continue;
                            }

//                            if (kid.getName().equalsIgnoreCase("meta")) {
//                                String metaname = kid.getAttributeValue(parser.NO_NAMESPACE, "name");
//                                String metavalue = kid.getAttributeValue(parser.NO_NAMESPACE, "content");
//                                if (metaname != null && metavalue != null
//                                        && !metaname.startsWith("calibre")) {
//                                    /*
//                                     * Ignore Calibre-specific tags,
//                                     * as they are not informative for the
//                                     * reader, but only for Calibre
//                                     */
//                                    meta.put(metaname, metavalue);
//                                }
//
//                                continue;
//                            }
//
//                            /*
//                             * It's a metadata then
//                             */
//                            {
//                                String metaname = kid.getName();
//                                String metavalue = text(kid);
//
//                                if (metaname != null && metavalue != null
//                                        && !metaname.startsWith("calibre")) {
//                                    meta.put(metaname, metavalue);
//                                }
//                            }
                        }
                    }
                } catch (Exception e) {
                    /*
                     * If there is a problem with the metadata,
                     * it's not worth bothering
                     */
                    //#debug
                    AlbiteMIDlet.LOGGER.log(e);
                }

                Hashtable manifest = new Hashtable(200);

                try {
                    /*
                     * Parse the manifest list
                     */
                    Element manifestEl = getElement(root, "manifest");

                    if (manifestEl == null) {
                        throw new BookException("No manifest tag in OPF");
                    }
                   
                    for (int i = 0; i < manifestEl.getChildCount(); i++) {
                        if (manifestEl.getType(i) != Node.ELEMENT) {
                            continue;
                        }

                        kid = manifestEl.getElement(i);

                        if (kid.getName().equalsIgnoreCase("item")) {
                            String id = kid.getAttributeValue(
                                    KXmlParser.NO_NAMESPACE, "id");
                            String href = kid.getAttributeValue(
                                    KXmlParser.NO_NAMESPACE, "href");

                            if (id != null && href != null) {
                                /*
                                 * Item is OK
                                 */
                                manifest.put(id, href);
                            }
                        }
                    }
                } catch (Exception e) {
                    //#debug
                    AlbiteMIDlet.LOGGER.log(e);
                    throw new BookException("couldn't parse manifest");
                }

                try {
                    /*
                     * Parse the spine and create the chapters
                     */
                    Vector chaps = new Vector(40);

                    Element spine = getElement(root, "spine");

                    if (spine == null) {
                        throw new BookException("No spine tag in OPF");
                    }

                    for (int i = 0; i < spine.getChildCount(); i++) {
                        if (spine.getType(i) != Node.ELEMENT) {
                            continue;
                        }

                        kid = spine.getElement(i);

                        if (kid.getName().equalsIgnoreCase("itemref")) {
                            String idref = kid.getAttributeValue(
                                    KXmlParser.NO_NAMESPACE, "idref");
                            if (idref != null) {
                                String href = (String) manifest.get(idref);

                                if (href != null) {
                                    ArchiveEntry entry =
                                            bookArchive.getEntry(
                                            RandomReadingFile
                                            .relativeToAbsoluteURL(
                                            opfFilePath + href));

                                    if (entry != null) {
                                        /*
                                         * chapter is OK
                                         */
//                                        final Chapter cur = loadChapter(
//                                                entry, chaps.size());
                                        splitChapterIntoPieces(
                                                entry,
                                                entry.fileSize(),
                                                entry,
                                                MAXIMUM_HTML_FILESIZE,
                                                chaps.size(),
                                                true,
                                                chaps
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

          } else {
            logger.debug("Adding entries from compressed file...");
            //read the entries from the zip file and copy them to the new zip archive
            //so that we don't have to recompress them.
            ZipArchiveInputStream currentZipStream = new ZipArchiveInputStream(currentFileStream);
            ArchiveEntry currentEntry;
            while ((currentEntry = currentZipStream.getNextEntry()) != null) {
              String entryName = currentEntry.getName();
              logger.debug("Zipping: " + entryName);
              ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName);
              try {
                newZipStream.putArchiveEntry(zipEntry);
              } catch (Exception e){
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

    TarArchiveInputStream tarIS = null;
    try {
      tarIS = new TarArchiveInputStream(data);

      // MINOR: Assumes the first entry in the tarball is a directory.
      ArchiveEntry entry;

      byte[] buf = new byte[32768];
      HashSet<String> names = new HashSet<String>();
      boolean gotMetadata = false;

outerTAR:    while(true) {
        try {
        entry = tarIS.getNextEntry();
        } catch (IllegalArgumentException e) {
          // Annoyingly, it can throw this on some corruptions...
          throw new ArchiveFailureException("Error reading archive: "+e.getMessage(), e);
        }
        if(entry == null) break;
        if(entry.isDirectory()) continue;
        String name = stripLeadingSlashes(entry.getName());
        if(names.contains(name)) {
          Logger.error(this, "Duplicate key "+name+" in archive "+key);
          continue;
        }
        long size = entry.getSize();
        if(name.equals(".metadata"))
          gotMetadata = true;
        if(size > maxArchivedFileSize && !name.equals(element)) {
          addErrorElement(ctx, key, name, "File too big: "+size+" greater than current archived file size limit "+maxArchivedFileSize, true);
        } else {
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

                } catch (IOException e2) {
                    input = new ZipArchiveInputStream(new FileInputStream(file));
                }
            }

            ArchiveEntry entry = input.getNextEntry();
            while (entry != null) {
                File f = new File(entry.getName());
                byte[] contents = new byte[(int) entry.getSize()];
                int offset = 0;
                int length = contents.length;

                while (offset < entry.getSize()) {
                    int actualRead = input.read(contents, offset, length);
                    length -= actualRead;
                    offset += actualRead;
                }

                if (!entry.isDirectory() && !ignored(f)) {
                    report(report, contents, f);
                }

                entry = input.getNextEntry();
            }
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

     * @throws SAXException if a SAX error occurs
     */
    public void unpack(ArchiveInputStream archive, XHTMLContentHandler xhtml)
            throws IOException, SAXException {
        try {
            ArchiveEntry entry = archive.getNextEntry();
            while (entry != null) {
                if (!entry.isDirectory()) {
                    xhtml.startElement("div", "class", "package-entry");
                    Metadata entrydata = new Metadata();
                    String name = entry.getName();
                    if (name != null && name.length() > 0) {
                        entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
                        xhtml.element("h1", name);
                    }
                    try {
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

                    ais = new TarArchiveInputStream(new GZIPInputStream(inputStream));
                } else {
                    InputStream inputStream = content.getContent();
                    ais = new ArchiveStreamFactory().createArchiveInputStream(artefact.getType(), inputStream);
                }
                ArchiveEntry entry = null;
                boolean needContainerHome = homeDir == null;
                while ((entry = ais.getNextEntry()) != null) {
                    File targetFile;
                    if (needContainerHome) {
                        targetFile = new File(targetDir, entry.getName());
                    } else {
                        targetFile = new File(homeDir, entry.getName());
                    }
                    if (!entry.isDirectory()) {
                        File parentDir = targetFile.getParentFile();
                        IllegalStateAssertion.assertTrue(parentDir.exists() || parentDir.mkdirs(), "Cannot create target directory: " + parentDir);

                        FileOutputStream fos = new FileOutputStream(targetFile);
                        IOUtils.copy(ais, fos);
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

        ArchiveInputStream in = null;
        try {
            in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(new FileInputStream(file)));
            final byte[] buff = new byte[1024];
            ArchiveEntry entry;
            while ((entry = in.getNextEntry()) != null) {
                final File extractTarget = new File(targetDir.getAbsolutePath(), entry.getName());
                if (entry.isDirectory()) {
                    extractTarget.mkdirs();
                } else {
                    final File parent = new File(extractTarget.getParent());
                    parent.mkdirs();
                    BufferedOutputStream out = null;
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

  protected Map<String, String> readArchive(ArchiveInputStream zip)
      throws IOException {
    Map<String, String> data = new HashMap<String, String>();

    while (true) {
      ArchiveEntry entry = zip.getNextEntry();
      if (entry == null) {
        break;
      }
     
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      IOUtils.copy(zip, bos);
      data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray()));
    }

    return data;
  }
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

    return data;
  }

  protected String readArchiveText(ArchiveInputStream zip) throws IOException {
    while (true) {
      ArchiveEntry entry = zip.getNextEntry();
      if (entry == null) {
        break;
      }

      if (!entry.getName().equals(UnpackerResource.TEXT_FILENAME)) {
        continue;
      }

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      IOUtils.copy(zip, bos);
View Full Code Here

Examples of org.apache.commons.compress.archivers.ArchiveEntry

                if (!isFilesOnly()) {
                    ensureParentDirs(out, r, addedDirectories);
                }

                ArchiveEntry ent = entryBuilder.buildEntry(r);
                out.putArchiveEntry(ent);
                if (!r.getResource().isDirectory()) {
                    InputStream in = null;
                    try {
                        in = r.getResource().getInputStream();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.