Class EncodingDetector


  • public class EncodingDetector
    extends java.lang.Object
    Utility class to detect the encoding of a stream by examining the initial bytes
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String inferStreamEncoding​(java.io.InputStream is, java.lang.String defaultEncoding, Logger err)
      Try to detect the encoding from the start of the input stream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EncodingDetector

        public EncodingDetector()
    • Method Detail

      • inferStreamEncoding

        public static java.lang.String inferStreamEncoding​(java.io.InputStream is,
                                                           java.lang.String defaultEncoding,
                                                           Logger err)
                                                    throws java.io.IOException
        Try to detect the encoding from the start of the input stream
        Parameters:
        is - the input stream
        defaultEncoding - the fallback encoding, normally UTF-8
        err - logger to be used for diagnostics, or null
        Returns:
        the inferred encoding, defaulting to UTF-8
        Throws:
        java.io.IOException - if it isn't possible to mark the current position on the input stream and read ahead