Package org.apache.commons.compress.compressors

Examples of org.apache.commons.compress.compressors.CompressorInputStream


    final ClassLoader classLoader = getClass().getClassLoader();
    final CompressorStreamFactory factory = new CompressorStreamFactory();

    public void testDetection() throws Exception {

        final CompressorInputStream bzip2 = getStreamFor("bla.txt.bz2");
        assertNotNull(bzip2);
        assertTrue(bzip2 instanceof BZip2CompressorInputStream);

        final CompressorInputStream gzip = getStreamFor("bla.tgz");
        assertNotNull(gzip);
        assertTrue(gzip instanceof GzipCompressorInputStream);

    }
View Full Code Here


    final ClassLoader classLoader = getClass().getClassLoader();
    final CompressorStreamFactory factory = new CompressorStreamFactory();

    public void testDetection() throws Exception {

        final CompressorInputStream bzip2 = getStreamFor("bla.txt.bz2");
        assertNotNull(bzip2);
        assertTrue(bzip2 instanceof BZip2CompressorInputStream);

        final CompressorInputStream gzip = getStreamFor("bla.tgz");
        assertNotNull(gzip);
        assertTrue(gzip instanceof GzipCompressorInputStream);

    }
View Full Code Here

      stream = new CloseShieldInputStream(stream);

      // Ensure that the stream supports the mark feature
      stream = new BufferedInputStream(stream);

      CompressorInputStream cis;
      try {
        CompressorStreamFactory factory = new CompressorStreamFactory();
        cis = factory.createCompressorInputStream(stream);
      } catch (CompressorException e) {
        throw new MorphlineRuntimeException("Unable to uncompress document stream", e);
View Full Code Here

      stream = new CloseShieldInputStream(stream);

      // Ensure that the stream supports the mark feature
      stream = new BufferedInputStream(stream);

      CompressorInputStream cis;
      try {
        CompressorStreamFactory factory = new CompressorStreamFactory();
        cis = factory.createCompressorInputStream(stream);
      } catch (CompressorException e) {
        throw new MorphlineRuntimeException("Unable to uncompress document stream", e);
View Full Code Here

            else if (MT_TAR.equals(type)) {
                final ArchiveInputStream archiveStream = new TarArchiveInputStream(bufferedResourceStream);
                importDataArchive(archive, archiveStream, options);
            }
            else if (MT_BZIP2.equals(type)) {
                final CompressorInputStream compressedStream = new BZip2CompressorInputStream(bufferedResourceStream);
                importDataArchive(archive, compressedStream, options);
            }
            else if (MT_GZIP.equals(type)) {
                final CompressorInputStream compressedStream = new GzipCompressorInputStream(bufferedResourceStream);
                importDataArchive(archive, compressedStream, options);
            }
            else if (MT_PACK200.equals(type)) {
                final CompressorInputStream compressedStream = new Pack200CompressorInputStream(bufferedResourceStream);
                importDataArchive(archive, compressedStream, options);
            }
            else if (MT_XZ.equals(type)) {
                final CompressorInputStream compressedStream = new XZCompressorInputStream(bufferedResourceStream);
                importDataArchive(archive, compressedStream, options);
            }
            else {
                throw new RuntimeException("Unrecognized archive media type: " + type);
            }
View Full Code Here

    private File uncompress(File gz) throws IOException, CompressorException {
        final File output = new File(gz.getParent(), FilenameUtils.getBaseName(gz.getName()));
        output.delete();

        final InputStream is = new FileInputStream(gz);
        final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz", is);
        IOUtils.copy(in, new FileOutputStream(output));
        in.close();

        return output;
    }
View Full Code Here

        stream = new CloseShieldInputStream(stream);

        // Ensure that the stream supports the mark feature
        stream = new BufferedInputStream(stream);

        CompressorInputStream cis;
        try {
            CompressorStreamFactory factory = new CompressorStreamFactory();
            CompressorParserOptions options =
                 context.get(CompressorParserOptions.class, new CompressorParserOptions() {
                     public boolean decompressConcatenated(Metadata metadata) {
                         return false;
                     }
                 });
            factory.setDecompressConcatenated(options.decompressConcatenated(metadata));
            cis = factory.createCompressorInputStream(stream);
        } catch (CompressorException e) {
            throw new TikaException("Unable to uncompress document stream", e);
        }

        MediaType type = getMediaType(cis);
        if (!type.equals(MediaType.OCTET_STREAM)) {
            metadata.set(CONTENT_TYPE, type.toString());
        }

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();

        try {
            Metadata entrydata = new Metadata();
            String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
            if (name != null) {
                if (name.endsWith(".tbz")) {
                    name = name.substring(0, name.length() - 4) + ".tar";
                } else if (name.endsWith(".tbz2")) {
                    name = name.substring(0, name.length() - 5) + ".tar";
                } else if (name.endsWith(".bz")) {
                    name = name.substring(0, name.length() - 3);
                } else if (name.endsWith(".bz2")) {
                    name = name.substring(0, name.length() - 4);
                } else if (name.endsWith(".xz")) {
                    name = name.substring(0, name.length() - 3);
                } else if (name.endsWith(".pack")) {
                    name = name.substring(0, name.length() - 5);
                } else if (name.length() > 0) {
                    name = GzipUtils.getUncompressedFilename(name);
                }
                entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
            }

            // Use the delegate parser to parse the compressed document
            EmbeddedDocumentExtractor extractor = context.get(
                    EmbeddedDocumentExtractor.class,
                    new ParsingEmbeddedDocumentExtractor(context));
            if (extractor.shouldParseEmbedded(entrydata)) {
                extractor.parseEmbedded(cis, xhtml, entrydata, true);
            }
        } finally {
            cis.close();
        }

        xhtml.endDocument();
    }
View Full Code Here

        stream = new CloseShieldInputStream(stream);

        // Ensure that the stream supports the mark feature
        stream = new BufferedInputStream(stream);

        CompressorInputStream cis;
        try {
            CompressorStreamFactory factory = new CompressorStreamFactory();
            CompressorParserOptions options =
                 context.get(CompressorParserOptions.class, new CompressorParserOptions() {
                     public boolean decompressConcatenated(Metadata metadata) {
                         return false;
                     }
                 });
            factory.setDecompressConcatenated(options.decompressConcatenated(metadata));
            cis = factory.createCompressorInputStream(stream);
        } catch (CompressorException e) {
            throw new TikaException("Unable to uncompress document stream", e);
        }

        MediaType type = getMediaType(cis);
        if (!type.equals(MediaType.OCTET_STREAM)) {
            metadata.set(CONTENT_TYPE, type.toString());
        }

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();

        try {
            Metadata entrydata = new Metadata();
            String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
            if (name != null) {
                if (name.endsWith(".tbz")) {
                    name = name.substring(0, name.length() - 4) + ".tar";
                } else if (name.endsWith(".tbz2")) {
                    name = name.substring(0, name.length() - 5) + ".tar";
                } else if (name.endsWith(".bz")) {
                    name = name.substring(0, name.length() - 3);
                } else if (name.endsWith(".bz2")) {
                    name = name.substring(0, name.length() - 4);
                } else if (name.endsWith(".xz")) {
                    name = name.substring(0, name.length() - 3);
                } else if (name.endsWith(".pack")) {
                    name = name.substring(0, name.length() - 5);
                } else if (name.length() > 0) {
                    name = GzipUtils.getUncompressedFilename(name);
                }
                entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
            }

            // Use the delegate parser to parse the compressed document
            EmbeddedDocumentExtractor extractor = context.get(
                    EmbeddedDocumentExtractor.class,
                    new ParsingEmbeddedDocumentExtractor(context));
            if (extractor.shouldParseEmbedded(entrydata)) {
                extractor.parseEmbedded(cis, xhtml, entrydata, true);
            }
        } finally {
            cis.close();
        }

        xhtml.endDocument();
    }
View Full Code Here

    }

    private static MediaType detectCompressorFormat(byte[] prefix, int length) {
        try {
            CompressorStreamFactory factory = new CompressorStreamFactory();
            CompressorInputStream cis = factory.createCompressorInputStream(
                    new ByteArrayInputStream(prefix, 0, length));
            try {
                return CompressorParser.getMediaType(cis);
            } finally {
                IOUtils.closeQuietly(cis);
View Full Code Here

    private File uncompress(File gz) throws IOException, CompressorException {
        final File output = new File(gz.getParent(), FilenameUtils.getBaseName(gz.getName()));
        output.delete();

        final InputStream is = new FileInputStream(gz);
        final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz", is);
        IOUtils.copy(in, new FileOutputStream(output));
        in.close();

        return output;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.compressors.CompressorInputStream

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.