Class StandardHtmlEncodingDetector

  • All Implemented Interfaces:
    Serializable, org.apache.tika.detect.EncodingDetector

    public final class StandardHtmlEncodingDetector
    extends Object
    implements org.apache.tika.detect.EncodingDetector
    An encoding detector that tries to respect the spirit of the HTML spec part 12.2.3 "The input byte stream", or at least the part that is compatible with the implementation of tika.

    https://html.spec.whatwg.org/multipage/parsing.html#the-input-byte-stream

    If a resource was fetched over HTTP, then HTTP headers should be added to tika metadata when using detect(java.io.InputStream, org.apache.tika.metadata.Metadata), especially HttpHeaders.CONTENT_TYPE, as it may contain charset information.

    This encoding detector may return null if no encoding is detected. It is meant to be used inside a CompositeEncodingDetector. For instance:

     
         EncodingDetector detector = new CompositeEncodingDetector(
           Arrays.asList(
             new StandardHtmlEncodingDetector(),
             new Icu4jEncodingDetector()));
     

    See Also:
    Serialized Form
    • Constructor Detail

      • StandardHtmlEncodingDetector

        public StandardHtmlEncodingDetector()
    • Method Detail

      • detect

        public Charset detect​(InputStream input,
                              org.apache.tika.metadata.Metadata metadata)
                       throws IOException
        Specified by:
        detect in interface org.apache.tika.detect.EncodingDetector
        Throws:
        IOException
      • getMarkLimit

        public int getMarkLimit()
      • setMarkLimit

        @Field
        public void setMarkLimit​(int markLimit)
        How far into the stream to read for charset detection. Default is 8192.