Package org.apache.commons.compress.archivers

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


        if (verbose) {
            getLog().info("Unpacking sphinx to " + sphinxSourceDirectory.getAbsolutePath());
        }
        try {
            ArchiveInputStream input = new ArchiveStreamFactory().createArchiveInputStream("jar", SphinxMojo.class.getResourceAsStream("/sphinx.jar"));
            ArchiveEntry entry = input.getNextEntry();
   
            while (entry != null) {
                File archiveEntry = new File(sphinxSourceDirectory, entry.getName());
                archiveEntry.getParentFile().mkdirs();
                if (entry.isDirectory()) {
                    archiveEntry.mkdir();
                    entry = input.getNextEntry();
                    continue;
                }
                OutputStream out = new FileOutputStream(archiveEntry);
View Full Code Here

            throw new RetrieverException(
                    "Unable to create extraction directory " + targetDirectory.getAbsolutePath());
        }

        ArchiveInputStream archiveInputStream = null;
        ArchiveEntry entry;
        try {

            final CountingInputStream inputStream = new CountingInputStream(new FileInputStream(inputArchive));

            final long inputFileSize = inputArchive.length();

            if(inputArchive.getName().endsWith(".tbz2")) {
                archiveInputStream = new TarArchiveInputStream(
                        new BZip2CompressorInputStream(inputStream));
            } else {
                archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(
                        new BufferedInputStream(inputStream));
            }

            final ProgressBar progressBar = new ProgressBar(inputFileSize);
            while ((entry = archiveInputStream.getNextEntry()) != null) {
                final File outputFile = new File(targetDirectory, entry.getName());

                // Entry is a directory.
                if (entry.isDirectory()) {
                    if (!outputFile.exists()) {
                        if(!outputFile.mkdirs()) {
                            throw new RetrieverException(
                                    "Could not create output directory " + outputFile.getAbsolutePath());
                        }
View Full Code Here

                    // Then untar it.
                    File uncompressedBinary = null;
                    final FileInputStream tarFileInputStream = new FileInputStream(tempTarFile);
                    final TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarFileInputStream);
                    ArchiveEntry entry;
                    while((entry = tarArchiveInputStream.getNextEntry()) != null) {
                        if("flashplayer".equals(entry.getName())) {
                            uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version, ".uexe");
                            final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(uncompressedBinary);
                            while(-1 != (n = tarArchiveInputStream.read(buffer))) {
                                uncompressedBinaryOutputStream.write(buffer, 0, n);
                            }
                            uncompressedBinaryOutputStream.close();
                        } else if("flashplayerdebugger".equals(entry.getName())) {
                            uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version, ".uexe");
                            final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(uncompressedBinary);
                            while(-1 != (n = tarArchiveInputStream.read(buffer))) {
                                uncompressedBinaryOutputStream.write(buffer, 0, n);
                            }
View Full Code Here

            for (int i = 0; i < ENTRIES.length; i++) {
                assertEquals(ENTRIES[i], zi.getNextEntry().getName());
            }

            // this is the last entry that is truncated
            ArchiveEntry lastEntry = zi.getNextEntry();
            assertEquals(LAST_ENTRY_NAME, lastEntry.getName());
            byte [] buffer = new byte [4096];

            // before the fix, we'd get 0 bytes on this read and all
            // subsequent reads thus a client application might enter
            // an infinite loop after the fix, we should get an
View Full Code Here

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

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

            for (Iterator it = workingSet.iterator(); it.hasNext();) {
                Change 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 it = workingSet.iterator(); it.hasNext();) {
View Full Code Here

        if (!changes.isEmpty()) {
            for (Iterator it = changes.iterator(); it.hasNext();) {
                Change change = (Change) it.next();
                if (change.type() == Change.TYPE_ADD
                        && change.getEntry() != null) {
                    ArchiveEntry entry = change.getEntry();

                    if(entry.equals(pChange.getEntry())) {
                        if(pChange.isReplaceMode()) {
                            it.remove();
                            changes.add(pChange);
                            return;
                        } else {
View Full Code Here

        final MemoryArchiveInputStream is = new MemoryArchiveInputStream(new String[][] {
                { "test1",     "content1" },
                { "test2",     "content2" },
                });

        final ArchiveEntry entry1 = is.getNextEntry();
        assertNotNull(entry1);
        assertEquals("test1", entry1.getName());
        final String content1 = is.readString();
        assertEquals("content1", content1);

        final ArchiveEntry entry2 = is.getNextEntry();
        assertNotNull(entry2);
        assertEquals("test2", entry2.getName());
        final String content2 = is.readString();
        assertEquals("content2", content2);

        final ArchiveEntry entry3 = is.getNextEntry();
        assertNull(entry3);

    }
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

        File result = File.createTempFile("dir-result", "");
        result.delete();
        result.mkdir();

        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

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.