Examples of CloseShieldInputStream


Examples of org.apache.tika.io.CloseShieldInputStream

            Iterator<ImageReader> iterator =
                ImageIO.getImageReadersByMIMEType(type);
            if (iterator.hasNext()) {
                ImageReader reader = iterator.next();
                reader.setInput(ImageIO.createImageInputStream(
                        new CloseShieldInputStream(stream)));
                metadata.set("height", Integer.toString(reader.getHeight(0)));
                metadata.set("width", Integer.toString(reader.getWidth(0)));
                reader.dispose();
            }
        }
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

    public void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context)
            throws IOException, SAXException, TikaException {
        // Protect the stream from being closed by CyberNeko
        stream = new CloseShieldInputStream(stream);

        // Prepare the input source using the encoding hint if available
        InputSource source = new InputSource(stream);
        String encoding = metadata.get(Metadata.CONTENT_ENCODING);
        if (encoding != null && Charset.isSupported(encoding)) {
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

        xhtml.startDocument();

        // At the end we want to close the gzip stream to release any associated
        // resources, but the underlying document stream should not be closed
        InputStream gzip =
            new GZIPInputStream(new CloseShieldInputStream(stream));
        try {
            Metadata entrydata = new Metadata();
            String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
            if (name != null && name.length() > 0) {
                entrydata.set(
                        Metadata.RESOURCE_NAME_KEY,
                        GzipUtils.getUncompressedFilename(name));
            }
            // Use the delegate parser to parse the compressed document
            super.parse(
                    new CloseShieldInputStream(gzip),
                    new EmbeddedContentHandler(
                            new BodyContentHandler(xhtml)),
                    entrydata, context);
        } finally {
            gzip.close();
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

                    xhtml.element("h1", name);
                }
                try {
                    // Use the delegate parser to parse this entry
                    super.parse(
                            new CloseShieldInputStream(archive),
                            new EmbeddedContentHandler(
                                    new BodyContentHandler(xhtml)),
                            entrydata, context);
                } catch (TikaException e) {
                    // Could not parse the entry, just skip the content
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

        xhtml.startDocument();

        // At the end we want to close the bzip2 stream to release any associated
        // resources, but the underlying document stream should not be closed
        InputStream bzip2 =
            new BZip2CompressorInputStream(new CloseShieldInputStream(stream));
        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);
                }
                entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
            }
            // Use the delegate parser to parse the compressed document
            super.parse(
                    new CloseShieldInputStream(bzip2),
                    new EmbeddedContentHandler(
                            new BodyContentHandler(xhtml)),
                    entrydata, context);
        } finally {
            bzip2.close();
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

        metadata.set(Metadata.CONTENT_TYPE, "application/x-tar");

        // At the end we want to close the tar stream to release any associated
        // resources, but the underlying document stream should not be closed
        TarArchiveInputStream tar =
            new TarArchiveInputStream(new CloseShieldInputStream(stream));
        try {
            parseArchive(tar, handler, metadata, context);
        } finally {
            tar.close();
        }
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

        metadata.set(Metadata.CONTENT_TYPE, "application/zip");

        // At the end we want to close the Zip stream to release any associated
        // resources, but the underlying document stream should not be closed
        ZipArchiveInputStream zip =
            new ZipArchiveInputStream(new CloseShieldInputStream(stream));
        try {
            parseArchive(zip, handler, metadata, context);
        } finally {
            zip.close();
        }
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

            Metadata metadata, ParseContext context)
            throws IOException, TikaException, SAXException {
        // At the end we want to close the cpio stream to release any associated
        // resources, but the underlying document stream should not be closed
        CpioArchiveInputStream cpio =
            new CpioArchiveInputStream(new CloseShieldInputStream(stream));
        try {
            parseArchive(cpio, handler, metadata, context);
        } finally {
            cpio.close();
        }
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

            Metadata metadata, ParseContext context)
            throws IOException, TikaException, SAXException {
        // At the end we want to close the ar stream to release any associated
        // resources, but the underlying document stream should not be closed
        ArArchiveInputStream ar =
            new ArArchiveInputStream(new CloseShieldInputStream(stream));
        try {
            parseArchive(ar, handler, metadata, context);
        } finally {
            ar.close();
        }
View Full Code Here

Examples of org.apache.tika.io.CloseShieldInputStream

            factory.setValidating(false);
            factory.setNamespaceAware(true);
            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            SAXParser parser = factory.newSAXParser();
            parser.parse(
                    new CloseShieldInputStream(stream),
                    new OfflineContentHandler(
                            new NSNormalizerContentHandler(dh)));
        } catch (ParserConfigurationException e) {
            throw new TikaException("XML parser configuration error", e);
        }
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.