Package org.apache.commons.compress.archivers

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


            }catch (IOException e) {
                //not found
            }
        }
        if(is != null || new File(managedSolrDir,parsedResourceName).isDirectory()){
            ArchiveInputStream ais;
            try {
                ais = ManagementUtils.getArchiveInputStream(resourceName, is);
            } catch (ArchiveException e) {
                throw new IOException("Unable to open ArchiveInputStream for resource '"+
                    resourceName+"'!",e);
View Full Code Here


                if(metadata != null){ //may be removed in the meantime
                    String currentArchive = metadata.getArchive();
                    boolean inSync = metadata.isSynchronized();
                    if(resource.equals(currentArchive)){ //current archive may be null
                        currentArchive = null; //reset the current archive to null (none)
                        ArchiveInputStream ais = null;
                        for(String archive : metadata.getIndexArchives()){
                            if(!archive.equals(resource)) {
                                if(currentArchive == null){
                                    try {
                                        InputStream is = provider.getInputStream(null, archive, null);
View Full Code Here

            return false; //never remove an registration after an unavailable event
        }
   
        @Override
        public boolean available(String resourceName, InputStream is) {
            ArchiveInputStream ais;
            try {
                ais = ManagementUtils.getArchiveInputStream(resourceName, is);
            } catch (ArchiveException e) {
                log.error("Unable to open ArchiveInputStream for Resource '"+
                    resourceName+"'!",e);
View Full Code Here

                                     + indexPath + "\"");
                        }
                        server.updateIndex(indexName, indexPath, props);
                        setFinishedState(ResourceState.INSTALLED);
                    } else {
                        ArchiveInputStream ais = null;
                        try {
                            ais = ConfigUtils.getArchiveInputStream(archiveFormat, is);
                            server.updateIndex(indexName, ais);
                            // we are done ... set the state to installed!
                            setFinishedState(ResourceState.INSTALLED);
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);
                IOUtils.copy(input, out);
                out.close();
                entry = input.getNextEntry();
            }
            input.close();
        }
        catch (Exception ex) {
            throw new MavenReportException("Could not unpack the sphinx source", ex);
        }
    }
View Full Code Here

        if (!targetDirectory.mkdirs()) {
            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());
                        }
                    }
                }

                // Entry is a file.
                else {
                    final byte[] data = new byte[BUFFER_MAX];
                    final FileOutputStream fos = new FileOutputStream(outputFile);
                    BufferedOutputStream dest = null;
                    try {
                        dest = new BufferedOutputStream(fos, BUFFER_MAX);

                        int count;
                        while ((count = archiveInputStream.read(data, 0, BUFFER_MAX)) != -1) {
                            dest.write(data, 0, count);
                            progressBar.updateProgress(inputStream.getBytesRead());
                        }
                    } finally {
                        if(dest != null) {
                            dest.flush();
                            dest.close();
                        }
                    }
                }

                progressBar.updateProgress(inputStream.getBytesRead());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ArchiveException e) {
            e.printStackTrace();
        } finally {
            if(archiveInputStream != null) {
                try {
                    archiveInputStream.close();
                } catch(Exception e) {
                    // Ignore...
                }
            }
        }
View Full Code Here

        OutputStream out3 = new ByteArrayOutputStream();
        File file = createSingleEntryArchive(archiverName);
        file.deleteOnExit();
       
        InputStream is1 = new FileInputStream(file);
        ArchiveInputStream ais1 = factory.createArchiveInputStream(archiverName, is1);
        final ArchiveEntry nextEntry = ais1.getNextEntry();
        assertNotNull(nextEntry);
       
        byte [] buff = new byte[10]; // small so multiple reads are needed;
        long size = nextEntry.getSize();
        if (size != ArchiveEntry.SIZE_UNKNOWN) {
            assertTrue("Size should be > 0, found: "+size, size > 0);
        }
       
        InputStream is2 = new FileInputStream(file);
        ArchiveInputStream ais2 = factory.createArchiveInputStream(archiverName, is2);
        final ArchiveEntry nextEntry2 = ais2.getNextEntry();
        assertNotNull(nextEntry2);
        assertEquals("Expected same entry size", size, nextEntry2.getSize());

        InputStream is3 = new FileInputStream(file);
        ArchiveInputStream ais3 = factory.createArchiveInputStream(archiverName, is3);
        final ArchiveEntry nextEntry3 = ais3.getNextEntry();
        assertNotNull(nextEntry3);
        assertEquals("Expected same entry size", size, nextEntry3.getSize());

        int b;
        while((b=ais1.read()) != -1){
            out1.write(b);
        }
        ais1.close();

        int bytes;
        while((bytes = ais2.read(buff)) > 0){
            out2.write(buff, 0, bytes);
        }
        ais2.close();
       
        while((bytes=ais3.read(buff, 0 , buff.length)) > 0){
            out3.write(buff, 0, bytes);
        }
        ais3.close();

        assertEquals("out1!=out2",out1.toString(),out2.toString());
        assertEquals("out1!=out3",out1.toString(),out3.toString());
    }
View Full Code Here

            // expected
        }
    }

    public void testCOMPRESS117() throws Exception {
        final ArchiveInputStream tar = getStreamFor("COMPRESS-117.tar");
        assertNotNull(tar);
        assertTrue(tar instanceof TarArchiveInputStream);
    }
View Full Code Here

        assertTrue(tar instanceof TarArchiveInputStream);
    }

    public void testDetection() throws Exception {

        final ArchiveInputStream ar = getStreamFor("bla.ar");
        assertNotNull(ar);
        assertTrue(ar instanceof ArArchiveInputStream);

        final ArchiveInputStream tar = getStreamFor("bla.tar");
        assertNotNull(tar);
        assertTrue(tar instanceof TarArchiveInputStream);

        final ArchiveInputStream zip = getStreamFor("bla.zip");
        assertNotNull(zip);
        assertTrue(zip instanceof ZipArchiveInputStream);

        final ArchiveInputStream jar = getStreamFor("bla.jar");
        assertNotNull(jar);
        assertTrue(jar instanceof ZipArchiveInputStream);

        final ArchiveInputStream cpio = getStreamFor("bla.cpio");
        assertNotNull(cpio);
        assertTrue(cpio instanceof CpioArchiveInputStream);

// Not yet implemented       
//        final ArchiveInputStream tgz = getStreamFor("bla.tgz");
View Full Code Here

    }

    private void checkEmptyArchive(String type) throws Exception{
        File ar = createEmptyArchive(type); // will be deleted by tearDown()
        ar.deleteOnExit(); // Just in case file cannot be deleted
        ArchiveInputStream ais = null;
        BufferedInputStream in = null;
        try {
            in = new BufferedInputStream(new FileInputStream(ar));
            ais = factory.createArchiveInputStream(in);
        } catch (ArchiveException ae) {
            fail("Should have recognised empty archive for "+type);
        } finally {
            if (ais != null) {
                ais.close(); // will close input as well
            } else if (in != null){
                in.close();
            }
        }
    }
View Full Code Here

TOP

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

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.