类 UniversalDetector

java.lang.Object
org.glavo.chardet.UniversalDetector

public final class UniversalDetector extends Object
  • 字段详细资料

    • MINIMUM_THRESHOLD

      public static final float MINIMUM_THRESHOLD
      另请参阅:
  • 构造器详细资料

    • UniversalDetector

      public UniversalDetector()
      Create UniversalDetector
    • UniversalDetector

      public UniversalDetector(CharsetListener listener)
      Create UniversalDetector
      参数:
      listener - a listener object that is notified of the detected encocoding. Can be null.
  • 方法详细资料

    • isDone

      public boolean isDone()
    • getDetectedCharset

      public DetectedCharset getDetectedCharset()
      返回:
      The detected encoding is returned. If the detector couldn't determine what encoding was used, null is returned.
    • setListener

      public void setListener(CharsetListener listener)
    • getListener

      public CharsetListener getListener()
    • handleData

      public void handleData(byte[] buf)
      Feed the detector with more data.
      参数:
      buf - Buffer with the data
    • handleData

      public void handleData(byte[] buf, int offset, int length)
      Feed the detector with more data.
      参数:
      buf - Buffer with the data
      offset - initial position of data in buf
      length - length of data
    • handleData

      public void handleData(ByteBuffer buf)
      Feed the detector with more data.

      This method only reads the buf and does not change its position.

      参数:
      buf - Buffer with the data
    • handleData

      public void handleData(ByteBuffer buf, int offset, int length)
      Feed the detector with more data.

      This method only reads the buf and does not change its position.

      参数:
      buf - Buffer with the data
      offset - initial position of data in buf
      length - length of data
    • detectCharsetFromBOM

      protected static DetectedCharset detectCharsetFromBOM(ByteBuffer buf, int offset)
    • dataEnd

      public void dataEnd()
      Marks end of data reading. Finish calculations.
    • reset

      public void reset()
      Resets detector to be used again.
    • detectCharset

      public static DetectedCharset detectCharset(File file) throws IOException
      Gets the charset of a File.
      参数:
      file - The file to check charset for
      返回:
      The charset of the file, null if it cannot be determined
      抛出:
      IOException - if some IO error occurs
    • detectCharset

      public static DetectedCharset detectCharset(Path path) throws IOException
      Gets the charset of a Path.
      参数:
      path - The path to file to check charset for
      返回:
      The charset of the file, null if it cannot be determined
      抛出:
      IOException - if some IO error occurs
    • detectCharset

      public static DetectedCharset detectCharset(InputStream inputStream) throws IOException
      Gets the charset of content from InputStream.
      参数:
      inputStream - InputStream containing text file
      返回:
      The charset of the file, null if it cannot be determined
      抛出:
      IOException - if some IO error occurs
    • detectCharset

      public static DetectedCharset detectCharset(ReadableByteChannel channel) throws IOException
      Gets the charset of content from InputStream.
      参数:
      channel - ReadableByteChannel containing text file
      返回:
      The charset of the file, null if it cannot be determined
      抛出:
      IOException - if some IO error occurs