Examples of ArchiveInputStream


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

     *
     */
    public void run(final RatReport report) throws RatException {

        try {
            ArchiveInputStream input;

            /* I am really sad that classes aren't first-class objects in
               Java :'( */
            try {
                input = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));
            } catch (IOException e) {
                try {
                    input = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file)));
                } 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();
            }

            input.close();
        } catch (IOException e) {
            throw new RatException(e);
        }
    }
View Full Code Here

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

            ResourceContent content = resource.adapt(ResourceContent.class);
            IllegalStateAssertion.assertNotNull(content, "Cannot obtain resource content for: " + artefact);

            try {
                ArchiveInputStream ais;
                if ("tar.gz".equals(artefact.getType())) {
                    InputStream inputStream = content.getContent();
                    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);
                        fos.close();

                        if (needContainerHome && homeDir == null) {
                            File currentDir = parentDir;
                            while (!currentDir.getParentFile().equals(targetDir)) {
                                currentDir = currentDir.getParentFile();
                            }
                            homeDir = currentDir;
                        }
                    }
                }
                ais.close();
            } catch (RuntimeException rte) {
                throw rte;
            } catch (Exception ex) {
                throw new IllegalStateException("Cannot extract artefact: " + artefact, ex);
            }
View Full Code Here

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

            file = extract(zipFile);
        } else {
            file = zipFile;
        }

        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;
                    try {
                        out = new BufferedOutputStream(new FileOutputStream(extractTarget));
                        int read;
                        while ((read = in.read(buff)) != -1) {
                            out.write(buff, 0, read);
                        }
                    } finally {
                        IoUtils.safeClose(out);
                    }
View Full Code Here

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

    }

    private static MediaType detectArchiveFormat(byte[] prefix, int length) {
        try {
            ArchiveStreamFactory factory = new ArchiveStreamFactory();
            ArchiveInputStream ais = factory.createArchiveInputStream(
                    new ByteArrayInputStream(prefix, 0, length));
            try {
                if ((ais instanceof TarArchiveInputStream)
                        && !TarArchiveInputStream.matches(prefix, length)) {
                    // ArchiveStreamFactory is too relaxed, see COMPRESS-117
View Full Code Here

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

  public void testDocWAV() throws Exception {
    Response response = WebClient.create(endPoint + UNPACKER_PATH)
        .type(APPLICATION_MSWORD).accept("application/zip")
        .put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));

    ArchiveInputStream zip = new ZipArchiveInputStream(
        (InputStream) response.getEntity());

    Map<String, String> data = readArchive(zip);
    assertEquals(WAV1_MD5, data.get(WAV1_NAME));
    assertEquals(WAV2_MD5, data.get(WAV2_NAME));
View Full Code Here

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

  public void testDocWAVText() throws Exception {
    Response response = WebClient.create(endPoint + ALL_PATH)
        .type(APPLICATION_MSWORD).accept("application/zip")
        .put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV));

    ArchiveInputStream zip = new ZipArchiveInputStream(
        (InputStream) response.getEntity());

    Map<String, String> data = readArchive(zip);
    assertEquals(WAV1_MD5, data.get(WAV1_NAME));
    assertEquals(WAV2_MD5, data.get(WAV2_NAME));
View Full Code Here

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

        }
    }

    private void expandStream(String name, InputStream stream, File dir)
        throws IOException {
        ArchiveInputStream is = null;
        try {
            is = factory.getArchiveStream(new BufferedInputStream(stream),
                                          getEncoding());
            expandArchiveStream(name, is, dir);
        } finally {
View Full Code Here

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

     */
    public InputStream getInputStream() throws IOException {
        if (isReference()) {
            return ((Resource) getCheckedRef()).getInputStream();
        }
        final ArchiveInputStream i = getStream();
        ArchiveEntry ae = null;
        while ((ae = i.getNextEntry()) != null) {
            if (ae.getName().equals(getName())) {
                return i;
            }
        }

View Full Code Here

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

    /**
     * fetches information from the named entry inside the archive.
     */
    protected void fetchEntry() {
        ArchiveInputStream i = null;
        try {
            i = getStream();
            ArchiveEntry ae = null;
            while ((ae = i.getNextEntry()) != null) {
                if (ae.getName().equals(getName())) {
                    setEntry(ae);
                    return;
                }
            }
View Full Code Here

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

        gid = EntryHelper.getGroupId(e);
    }

    private ArchiveInputStream getStream() throws IOException {
        Resource archive = getArchive();
        ArchiveInputStream s = StreamHelper.getInputStream(factory, archive,
                                                           getEncoding());
        return s != null ? s :
            factory.getArchiveStream(new BufferedInputStream(archive
                                                             .getInputStream()),
                                     getEncoding());
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.