public class UniversalDetector extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
UniversalDetector.InputState |
| Modifier and Type | Field and Description |
|---|---|
static float |
MINIMUM_THRESHOLD |
static float |
SHORTCUT_THRESHOLD |
| Constructor and Description |
|---|
UniversalDetector() |
UniversalDetector(CharsetListener listener) |
| Modifier and Type | Method and Description |
|---|---|
void |
dataEnd()
Marks end of data reading.
|
static String |
detectCharset(File file)
Gets the charset of a File.
|
static String |
detectCharset(InputStream inputStream)
Gets the charset of content from InputStream.
|
static String |
detectCharset(Path path)
Gets the charset of a Path.
|
static String |
detectCharsetFromBOM(byte[] buf) |
String |
getDetectedCharset() |
CharsetListener |
getListener() |
void |
handleData(byte[] buf)
Feed the detector with more data
|
void |
handleData(byte[] buf,
int offset,
int length)
Feed the detector with more data
|
boolean |
isDone() |
void |
reset()
Resets detector to be used again.
|
void |
setListener(CharsetListener listener) |
public static final float SHORTCUT_THRESHOLD
public static final float MINIMUM_THRESHOLD
public UniversalDetector()
public UniversalDetector(CharsetListener listener)
listener - a listener object that is notified of
the detected encocoding. Can be null.public boolean isDone()
public String getDetectedCharset()
public void setListener(CharsetListener listener)
public CharsetListener getListener()
public void handleData(byte[] buf)
buf - The buffer containing the datapublic void handleData(byte[] buf,
int offset,
int length)
buf - Buffer with the dataoffset - initial position of data in buflength - length of datapublic static String detectCharsetFromBOM(byte[] buf)
public void dataEnd()
public final void reset()
public static String detectCharset(File file) throws IOException
file - The file to check charset forIOException - if some IO error occurspublic static String detectCharset(Path path) throws IOException
path - The path to file to check charset forIOException - if some IO error occurspublic static String detectCharset(InputStream inputStream) throws IOException
inputStream - InputStream containing text fileIOException - if some IO error occursCopyright © 2024. All rights reserved.