Package org.apache.commons.compress.archivers

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


    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());
                outfile.getParentFile().mkdirs();
                OutputStream out = new FileOutputStream(outfile);
                long copied=0;
                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: " + entry.getName());
                }
            }
            in.close();
            if (expected != null && expected.size() > 0) {
                for (Iterator iterator = expected.iterator(); iterator.hasNext();) {
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

        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

        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

        TarArchiveOutputStream tos = new TarArchiveOutputStream(out);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        // byte[] buf = Streams.readBytes(new FileInputStream("C:\\wendal.ts"));
        for (int i = 0; i < 2; i++) {
            try {
                ArchiveEntry entry = tos.createArchiveEntry(new File("C:\\Q.zip"),
                                                            Strings.dup('A', 500) + i);
                tos.putArchiveEntry(entry);
                // tos.write(buf);
            tos.closeArchiveEntry();
            }
View Full Code Here

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

        while (entryIterator.hasNext()) {
            ArchiveEntry entry = entryIterator.next();
            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(entryIterator.getInputStream(), 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

        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);

        is.close();
    }
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.