Class UniversalDetector
java.lang.Object
org.mozilla.universalchardet.UniversalDetector
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum///////////////////////////////////////////////////////////// -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate booleanprivate CharsetProberprivate booleanprivate UniversalDetector.InputState/////////////////////////////////////////////////////////////private byteprivate CharsetListenerstatic final floatprivate booleanprivate CharsetProber[]static final float/////////////////////////////////////////////////////////////private boolean -
Constructor Summary
ConstructorsConstructorDescription/////////////////////////////////////////////////////////////UniversalDetector(CharsetListener listener) -
Method Summary
Modifier and TypeMethodDescriptionvoiddataEnd()Marks end of data reading.static StringdetectCharset(File file) Gets the charset of a File.static StringdetectCharset(InputStream inputStream) Gets the charset of content from InputStream.static StringdetectCharset(Path path) Gets the charset of a Path.static StringdetectCharsetFromBOM(byte[] buf) private static StringdetectCharsetFromBOM(byte[] buf, int offset) voidhandleData(byte[] buf) Feed the detector with more datavoidhandleData(byte[] buf, int offset, int length) Feed the detector with more databooleanisDone()final voidreset()Resets detector to be used again.voidsetListener(CharsetListener listener)
-
Field Details
-
SHORTCUT_THRESHOLD
public static final float SHORTCUT_THRESHOLD/////////////////////////////////////////////////////////////- See Also:
-
MINIMUM_THRESHOLD
public static final float MINIMUM_THRESHOLD- See Also:
-
inputState
///////////////////////////////////////////////////////////// -
done
private boolean done -
start
private boolean start -
gotData
private boolean gotData -
onlyPrintableASCII
private boolean onlyPrintableASCII -
lastChar
private byte lastChar -
detectedCharset
-
probers
-
escCharsetProber
-
listener
-
-
Constructor Details
-
UniversalDetector
public UniversalDetector()///////////////////////////////////////////////////////////// -
UniversalDetector
- Parameters:
listener- a listener object that is notified of the detected encocoding. Can be null.
-
-
Method Details
-
isDone
public boolean isDone() -
getDetectedCharset
- Returns:
- The detected encoding is returned. If the detector couldn't determine what encoding was used, null is returned.
-
setListener
-
getListener
-
handleData
public void handleData(byte[] buf) Feed the detector with more data- Parameters:
buf- The buffer containing the data
-
handleData
public void handleData(byte[] buf, int offset, int length) Feed the detector with more data- Parameters:
buf- Buffer with the dataoffset- initial position of data in buflength- length of data
-
detectCharsetFromBOM
-
detectCharsetFromBOM
-
dataEnd
public void dataEnd()Marks end of data reading. Finish calculations. -
reset
public final void reset()Resets detector to be used again. -
detectCharset
Gets the charset of a File.- Parameters:
file- The file to check charset for- Returns:
- The charset of the file, null if cannot be determined
- Throws:
IOException- if some IO error occurs
-
detectCharset
Gets the charset of a Path.- Parameters:
path- The path to file to check charset for- Returns:
- The charset of the file, null if cannot be determined
- Throws:
IOException- if some IO error occurs
-
detectCharset
Gets the charset of content from InputStream.- Parameters:
inputStream- InputStream containing text file- Returns:
- The charset of the file, null if cannot be determined
- Throws:
IOException- if some IO error occurs
-