Package org.apache.commons.compress.archivers.sevenz

Examples of org.apache.commons.compress.archivers.sevenz.SevenZFile


            outArchive.closeArchiveEntry();
        } finally {
            outArchive.close();
        }
       
        final SevenZFile archive = new SevenZFile(output);
        try {
            SevenZArchiveEntry entry;
           
            entry = archive.getNextEntry();
            assert(entry != null);
            assertEquals(entry.getName(), file1.getName());
           
            entry = archive.getNextEntry();
            assert(entry != null);
            assertEquals(entry.getName(), file2.getName());
           
            assert(archive.getNextEntry() == null);
        } finally {
            archive.close();
        }
    }
View Full Code Here


        return new SevenZOutputStream(new SevenZOutputFile(archive));
    }

    @Override
    protected ArchiveInputStream createArchiveInputStream(File archive) throws IOException {
        return new SevenZInputStream(new SevenZFile(archive));
    }
View Full Code Here

        if(archive.exists() && archive.canRead()) {

            if(archive.getName().endsWith("7z")) {
                log.info("auto-detected archive format: 7Z");

                final SevenZFile sevenZFile = new SevenZFile(archive);

                try {
                    SevenZArchiveEntry entry;
                    while( (entry = sevenZFile.getNextEntry()) != null) {

                        if(! entry.isDirectory()) {
                            log.info("loading entry {} ...", entry.getName());

                            // detect the file format
                            RDFFormat detectedFormat = Rio.getParserFormatForFileName(entry.getName());
                            if(format == null) {
                                if(detectedFormat != null) {
                                    log.info("auto-detected entry format: {}", detectedFormat.getName());
                                    format = detectedFormat;
                                } else {
                                    throw new RDFParseException("could not detect input format of entry "+ entry.getName());
                                }
                            } else {
                                if(detectedFormat != null && !format.equals(detectedFormat)) {
                                    log.warn("user-specified entry format ({}) overrides auto-detected format ({})", format.getName(), detectedFormat.getName());
                                } else {
                                    log.info("user-specified entry format: {}", format.getName());
                                }
                            }


                            load(new InputStream() {
                                @Override
                                public int read() throws IOException {
                                    return sevenZFile.read();
                                }

                                @Override
                                public int read(byte[] b) throws IOException {
                                    return sevenZFile.read(b);
                                }

                                @Override
                                public int read(byte[] b, int off, int len) throws IOException {
                                    return sevenZFile.read(b, off, len);
                                }
                            },handler,format);
                        }
                    }
                } finally {
                    sevenZFile.close();
                }

            } else {
                InputStream in;
View Full Code Here

        File f = getSevenZFile();
        if (f == null) {
            return super.getInputStream();
        }

        final SevenZFile z = new SevenZFile(f);
        SevenZArchiveEntry ze = z.getNextEntry();
        while (ze != null) {
            if (ze.getName().equals(getName())) {
                return new InputStream() {
                    public int read() throws IOException {
                        return z.read();
                    }
                    public int read(byte[] b) throws IOException {
                        return z.read(b);
                    }
                    public void close() throws IOException {
                        z.close();
                    }
                    protected void finalize() throws Throwable {
                        try {
                            close();
                        } finally {
                            super.finalize();
                        }
                    }
                };
            }
            ze = z.getNextEntry();
        }
        z.close();
        throw new BuildException("no entry " + getName() + " in "
                                 + getArchive());
    }
View Full Code Here

        if (f == null) {
            super.fetchEntry();
            return;
        }

        SevenZFile z = null;
        try {
            z = new SevenZFile(f);
            SevenZArchiveEntry ze = z.getNextEntry();
            while (ze != null) {
                if (ze.getName().equals(getName())) {
                    setEntry(ze);
                    return;
                }
                ze = z.getNextEntry();
            }
            setEntry(null);
        } catch (IOException e) {
            log(e.getMessage(), Project.MSG_DEBUG);
            throw new BuildException(e);
        } finally {
            if (z != null) {
                try {
                    z.close();
                } catch (IOException ex) {
                    // swallow
                }
            }
        }
View Full Code Here

            return;
        }

        File srcFile = fp.getFile();
        SevenZArchiveEntry entry = null;
        SevenZFile zf = null;

        try {
            try {
                zf = new SevenZFile(srcFile);
                entry = zf.getNextEntry();
                while (entry != null) {
                    /* TODO implement canReadEntryData in CC
                    if (getSkipUnreadableEntries() && !zf.canReadEntryData(entry)) {
                        log(Messages.skippedIsUnreadable(entry));
                        continue;
                    }
                    */
                    Resource r = new SevenZResource(srcFile, encoding, entry);
                    String name = entry.getName();
                    if (entry.isDirectory()) {
                        name = trimSeparator(name);
                        dirEntries.put(name, r);
                        if (match(name)) {
                            matchDirEntries.put(name, r);
                        }
                    } else {
                        fileEntries.put(name, r);
                        if (match(name)) {
                            matchFileEntries.put(name, r);
                        }
                    }
                    entry = zf.getNextEntry();
                }
            } catch (IOException ex) {
                throw new BuildException("Problem opening " + srcFile, ex);
            }
        } finally {
            if (zf != null) {
                try {
                    zf.close();
                } catch (IOException ex) {
                    // swallow
                }
            }
        }
View Full Code Here

    private static class SevenZArchiveInputStream extends ArchiveInputStream {

        private final SevenZFile zipFile;

        public SevenZArchiveInputStream(File file) throws IOException {
            zipFile = new SevenZFile(file);
        }
View Full Code Here

                                     + " as the file does not exist",
                                     getLocation());
        }
        log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
        FileNameMapper mapper = getMapper();
        SevenZFile outer = null;
        try {
            final SevenZFile zf = outer = new SevenZFile(srcF);
            boolean empty = true;
            SevenZArchiveEntry ze = zf.getNextEntry();
            while (ze != null) {
                empty = false;
                /* TODO implement canReadEntryData in CC
                if (getSkipUnreadableEntries() && !zf.canReadEntryData(ze)) {
                    log(Messages.skippedIsUnreadable(ze));
                    continue;
                }
                */
                log("extracting " + ze.getName(), Project.MSG_DEBUG);
                InputStream is = null;
                try {
                    extractFile(fileUtils, srcF, dir,
                                is = new InputStream() {
                                        public int read() throws IOException {
                                            return zf.read();
                                        }
                                        public int read(byte[] b) throws IOException {
                                            return zf.read(b);
                                        }
                                    },
                                ze.getName(), ze.getLastModifiedDate(),
                                ze.isDirectory(), mapper);
                } finally {
                    FileUtils.close(is);
                }
                ze = zf.getNextEntry();
            }
            if (empty && getFailOnEmptyArchive()) {
                throw new BuildException("archive '" + srcF + "' is empty");
            }
            log("expand complete", Project.MSG_VERBOSE);
View Full Code Here

                // Rework as a file, and wrap
                stream.reset();
                TikaInputStream tstream = TikaInputStream.get(stream);
               
                // Pending a fix for COMPRESS-269, this bit is a little nasty
                ais = new SevenZWrapper(new SevenZFile(tstream.getFile()));
            } else {
                throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne);
            }
        } catch (ArchiveException e) {
            throw new TikaException("Unable to unpack document stream", e);
View Full Code Here

                // Rework as a file, and wrap
                stream.reset();
                TikaInputStream tstream = TikaInputStream.get(stream, tmp);
               
                // Pending a fix for COMPRESS-269, this bit is a little nasty
                ais = new SevenZWrapper(new SevenZFile(tstream.getFile()));
               
            } else {
                tmp.close();
                throw new TikaException("Unknown non-streaming format " + sne.getFormat(), sne);
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.sevenz.SevenZFile

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.