Package com.norconex.importer.charset
Class CharsetDetector
java.lang.Object
com.norconex.importer.charset.CharsetDetector
Character set detector.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCharsetDetector(Charset declaredCharset, Charset fallbackCharset, Supplier<Object> priorityCharset) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Detects a document character using the following logic, in order:detect(InputStream input) Detects the character encoding of an input stream.Detects the character encoding of a string.
-
Constructor Details
-
CharsetDetector
-
-
Method Details
-
builder
-
detect
Detects a document character using the following logic, in order:
-
If the document is
null, returns the fallback charset (which is UTF-8 unless explicitly set to something different). -
If priority charset supplier is not
nulland returns a valid charset, returns that charset. -
If the charset has already been detected for the document, returns
that charset (
Doc.getCharset()). - Try to detect the character set, using any declared charset to influence the outcome.
- If it can't be detected, returns the declared charset.
- If no declared charset, returns the fallback charset (UTF-8 by default).
This method will NOT set the detected encoding on the
DocHandlerContext.- Parameters:
doc- document to detect encoding on when applicable- Returns:
- the detected charset (never
null). - Throws:
IOException- problem detecting charset
-
If the document is
-
detect
Detects the character encoding of a string.
Detection occurs using the following logic, in order:
-
If the string is
null, returns the fallback charset (which is UTF-8 unless explicitly set to something different). -
If priority charset supplier is not
nulland returns a valid charset, returns that charset. - Try to detect the character set, using any declared charset to influence the outcome.
- If it can't be detected, returns the declared charset.
- If no declared charset, returns the fallback charset (UTF-8 by default).
- Parameters:
input- the input stream to detect encoding on- Returns:
- the detected charset (never
null).
-
If the string is
-
detect
Detects the character encoding of an input stream.
InputStream.markSupported()must returntrueotherwise no decoding will be attempted and the fallback charset will be returned.Detection occurs using the following logic, in order:
-
If the stream is
nullor does not support marking, returns the fallback charset (which is UTF-8 unless explicitly set to something different). -
If priority charset supplier is not
nulland returns a valid charset, returns that charset. - Try to detect the character set, using any declared charset to influence the outcome.
- If it can't be detected, returns the declared charset.
- If no declared charset, returns the fallback charset (UTF-8 by default).
- Parameters:
input- the input stream to detect encoding on- Returns:
- the detected charset (never
null). - Throws:
IOException- problem detecting charset
-
If the stream is
-