Class WriteOutContentHandler

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
    Direct Known Subclasses:
    LanguageHandler, ProfilingHandler, RichTextContentHandler

    public class WriteOutContentHandler
    extends ContentHandlerDecorator
    SAX event handler that writes content up to an optional write limit out to a character stream or other decorated handler.
    • Constructor Summary

      Constructors 
      Constructor Description
      WriteOutContentHandler()
      Creates a content handler that writes character events to an internal string buffer.
      WriteOutContentHandler​(int writeLimit)
      Creates a content handler that writes character events to an internal string buffer.
      WriteOutContentHandler​(java.io.OutputStream stream)
      Creates a content handler that writes character events to the given output stream using the default encoding.
      WriteOutContentHandler​(java.io.Writer writer)
      Creates a content handler that writes character events to the given writer.
      WriteOutContentHandler​(java.io.Writer writer, int writeLimit)
      Creates a content handler that writes content up to the given write limit to the given character stream.
      WriteOutContentHandler​(org.xml.sax.ContentHandler handler, int writeLimit)
      Creates a content handler that writes content up to the given write limit to the given content handler.
    • Constructor Detail

      • WriteOutContentHandler

        public WriteOutContentHandler​(org.xml.sax.ContentHandler handler,
                                      int writeLimit)
        Creates a content handler that writes content up to the given write limit to the given content handler.
        Parameters:
        handler - content handler to be decorated
        writeLimit - write limit
        Since:
        Apache Tika 0.10
      • WriteOutContentHandler

        public WriteOutContentHandler​(java.io.Writer writer,
                                      int writeLimit)
        Creates a content handler that writes content up to the given write limit to the given character stream.
        Parameters:
        writer - character stream
        writeLimit - write limit
        Since:
        Apache Tika 0.10
      • WriteOutContentHandler

        public WriteOutContentHandler​(java.io.Writer writer)
        Creates a content handler that writes character events to the given writer.
        Parameters:
        writer - writer
      • WriteOutContentHandler

        public WriteOutContentHandler​(java.io.OutputStream stream)
        Creates a content handler that writes character events to the given output stream using the default encoding.
        Parameters:
        stream - output stream
      • WriteOutContentHandler

        public WriteOutContentHandler​(int writeLimit)
        Creates a content handler that writes character events to an internal string buffer. Use the ContentHandlerDecorator.toString() method to access the collected character content.

        The internal string buffer is bounded at the given number of characters. If this write limit is reached, then a SAXException is thrown. The isWriteLimitReached(Throwable) method can be used to detect this case.

        Parameters:
        writeLimit - maximum number of characters to include in the string, or -1 to disable the write limit
        Since:
        Apache Tika 0.7
      • WriteOutContentHandler

        public WriteOutContentHandler()
        Creates a content handler that writes character events to an internal string buffer. Use the ContentHandlerDecorator.toString() method to access the collected character content.

        The internal string buffer is bounded at 100k characters. If this write limit is reached, then a SAXException is thrown. The isWriteLimitReached(Throwable) method can be used to detect this case.

    • Method Detail

      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Writes the given characters to the given character stream.
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class ContentHandlerDecorator
        Throws:
        org.xml.sax.SAXException
      • ignorableWhitespace

        public void ignorableWhitespace​(char[] ch,
                                        int start,
                                        int length)
                                 throws org.xml.sax.SAXException
        Specified by:
        ignorableWhitespace in interface org.xml.sax.ContentHandler
        Overrides:
        ignorableWhitespace in class ContentHandlerDecorator
        Throws:
        org.xml.sax.SAXException
      • isWriteLimitReached

        public boolean isWriteLimitReached​(java.lang.Throwable t)
        Checks whether the given exception (or any of it's root causes) was thrown by this handler as a signal of reaching the write limit.
        Parameters:
        t - throwable
        Returns:
        true if the write limit was reached, false otherwise
        Since:
        Apache Tika 0.7