Package org.apache.commons.compress.archivers

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


            is = new BZip2CompressorInputStream(is);
            name = FilenameUtils.removeExtension(name);
            log.debug("   - from BZip2 Archive");
        } else if ("zip".equalsIgnoreCase(FilenameUtils.getExtension(name))) {
            ZipArchiveInputStream zipin = new ZipArchiveInputStream(is);
            ArchiveEntry entry = zipin.getNextEntry();
            log.info("For ZIP archives only the 1st Entry will be processed!");
            name = FilenameUtils.getName(entry.getName());
            log.info("  - processed Entry: {}",entry.getName());
        } else { // else uncompressed data ...
            log.info("  - uncompressed source: {}",name);
        }
        MediaType mediaType;
        if(settings.getTestDataMediaType() != null){
View Full Code Here


                                            + " extists but is not a directory!");
        }
        if (coreName == null || coreName.isEmpty()) {
            throw new IllegalArgumentException("The parsed core name MUST NOT be NULL or empty!");
        }
        ArchiveEntry entry;
        while ((entry = ais.getNextEntry()) != null) {
            if (!entry.isDirectory()) {
                copyArchiveEntry(ais, entry, coreDir, coreName, override);
                /*
                 * NOTE: Here we use the coreName as context (last argument to prepairCopy(..)). This ensures
                 * that it matter if the archive contains the data directly in the root or within an folder
                 * with the name of the core.
View Full Code Here

     * @throws IOException
     * @throws FileNotFoundException
     */
    private void addArchiveEntry(ArchiveOutputStream out, String filename, final File infile)
            throws IOException, FileNotFoundException {
        ArchiveEntry entry = out.createArchiveEntry(infile, filename);
        out.putArchiveEntry(entry);
        IOUtils.copy(new FileInputStream(infile), out);
        out.closeArchiveEntry();
        archiveList.add(filename);
    }
View Full Code Here

            throws Exception {
        File result = mkdir("dir-result");
        result.deleteOnExit();

        try {
            ArchiveEntry entry = null;
            while ((entry = in.getNextEntry()) != null) {
                File outfile = new File(result.getCanonicalPath() + "/result/"
                        + entry.getName());
                long copied=0;
                if (entry.isDirectory()){
                    outfile.mkdirs();
                } else {
                    outfile.getParentFile().mkdirs();
                    OutputStream out = new FileOutputStream(outfile);
                    try {
                        copied=IOUtils.copy(in, out);
                    } finally {
                        out.close();
                    }                   
                }
                final long size = entry.getSize();
                if (size != ArchiveEntry.SIZE_UNKNOWN) {
                    assertEquals("Entry.size should equal bytes read.",size, copied);
                }

                if (!outfile.exists()) {
                    fail("extraction failed: " + entry.getName());
                }
                if (expected != null && !expected.remove(getExpectedString(entry))) {
                    fail("unexpected entry: " + getExpectedString(entry));
                }
            }
View Full Code Here

                it.remove();
                results.addedFromChangeSet(change.getEntry().getName());
            }
        }

        ArchiveEntry entry = null;
        while ((entry = in.getNextEntry()) != null) {
            boolean copy = true;

            for (Iterator<Change> it = workingSet.iterator(); it.hasNext();) {
                Change change = it.next();

                final int type = change.type();
                final String name = entry.getName();
                if (type == Change.TYPE_DELETE && name != null) {
                    if (name.equals(change.targetFile())) {
                        copy = false;
                        it.remove();
                        results.deleted(name);
                        break;
                    }
                } else if (type == Change.TYPE_DELETE_DIR && name != null) {
                    // don't combine ifs to make future extensions more easy
                    if (name.startsWith(change.targetFile() + "/")) { // NOPMD
                        copy = false;
                        results.deleted(name);
                        break;
                    }
                }
            }

            if (copy
                && !isDeletedLater(workingSet, entry)
                && !results.hasBeenAdded(entry.getName())) {
                copyStream(in, out, entry);
                results.addedFromStream(entry.getName());
            }
        }
       
        // Adds files which hasn't been added from the original and do not have replace mode on
        for (Iterator<Change> it = workingSet.iterator(); it.hasNext();) {
View Full Code Here

        ArchiveInputStream input = null;
        try {
            input = createArchiveInputStream(archive);

            ArchiveEntry entry;
            while ((entry = input.getNextEntry()) != null) {
                File file = new File(destination, entry.getName());

                if (entry.isDirectory()) {
                    file.mkdirs();
                } else {
                    file.getParentFile().mkdirs();
                    IOUtils.copy(input, file);
                }
View Full Code Here

     * @param entryName the name of the archive entry
     * @param archive the archive to write to
     * @throws IOException when an I/O error occurs during FileInputStream creation or during copying
     */
    protected void createArchiveEntry(File file, String entryName, ArchiveOutputStream archive) throws IOException {
        ArchiveEntry entry = archive.createArchiveEntry(file, entryName);
        // TODO #23: read permission from file, write it to the ArchiveEntry
        archive.putArchiveEntry(entry);

        if (!entry.isDirectory()) {
            FileInputStream input = null;
            try {
                input = new FileInputStream(file);
                IOUtils.copy(input, archive);
            } finally {
View Full Code Here

        try {
            if (targetDir.exists()) {
                FileUtils.forceDelete(targetDir);
            }
            targetDir.mkdirs();
            ArchiveEntry entry = is.getNextEntry();
            while (entry != null) {
                String name = entry.getName();
                name = name.substring(name.indexOf("/") + 1);
                File file = new File(targetDir, name);
                if (entry.isDirectory()) {
                    file.mkdirs();
                } else {
                    file.getParentFile().mkdirs();
                    OutputStream os = new FileOutputStream(file);
                    try {
View Full Code Here

     * @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()) {
                    String name = entry.getName();

                    if (archive.canReadEntryData(entry)) {
                        Metadata entrydata = new Metadata();
                        if (name != null && name.length() > 0) {
                            entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
View Full Code Here

                    input = new ArchiveStreamFactory()
                            .createArchiveInputStream(new BufferedInputStream(new GzipCompressorInputStream(readableArFile.open())));
                } catch (ArchiveException e) {
                    throw new IOException(e);
                }
                ArchiveEntry ae;
                while ((ae = input.getNextEntry()) != null) {
                    if (ae.getName().endsWith("control")) {
                        return IOUtils.readLines(input);
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.ArchiveEntry

Copyright © 2018 www.massapicom. 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.