public class ByteOrderMarkDetector extends AbstractCodepageDetector implements ICodepageDetector
This detector identifies byte order marks of the following codepages to give a 100 % deterministic result in case of detection.
| 00 00 FE FF | UCS-4, big-endian machine (1234 order) |
| FF FE 00 00 | UCS-4,little-endian machine (4321 order) |
| 00 00 FF FE | UCS-4, unusual octet order (2143) |
| FE FF 00 00 | UCS-4, unusual octet order (3412) |
| FE FF ## ## | UTF-16, big-endian |
| FF FE ## ## | UTF-16, little-endian |
| EF BB BF | UTF-8 |
Note that this detector is very fast as it only has to read a maximum of 8 bytes to provide a
result. Nevertheless it is senseless to add it to the configuration if the documents to detect
will have a low rate of documents in the codepages that will be detected. If added to the
configuration of CodepageDetectorProxy it should be at
front position to save computations of the following detection processses.
This implementation is based on:
W3C XML Specification
1.0 3rd Edition, F.1 Detection Without External Encoding Information .
UnicodeDetector but with a different
read strategy (read each byte separately) and a switch case tree (-> bytecode tableswitch). Would
be great to have a performance comparison. Maybe the read of 4 bytes in a row combined with the
switch could make this implementation the winner.
| 构造器和说明 |
|---|
ByteOrderMarkDetector() |
| 限定符和类型 | 方法和说明 |
|---|---|
Charset |
detectCodepage(InputStream in,
int length)
This method allows to detect the charset encoding from every source (even a
String, which an URL does not decorate!).
|
Charset |
detectCodepage(URL url)
Delegates to
detectCodepage(InputStream, int)with a buffered input stream of size 10
(8 needed as maximum). |
compareTo, openclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitopencompareTopublic Charset detectCodepage(InputStream in, int length) throws IOException
ICodepageDetectorThis method allows to detect the charset encoding from every source (even a String, which an URL does not decorate!).
Note that you cannot reuse the given InputStream unless it supports marking (InputStream.markSupported() ==
true), you mark the initial position with a sufficient readlimit and invoke
reset afterwards (without getting any exception).
detectCodepage 在接口中 ICodepageDetectorin - An InputStream for the document, that supports mark and a
readlimit of argument length.length - The amount of bytes to take into account. This number should not
be longer than the amount of bytes retrievable from the
InputStream but should be as long as possible to give the fallback
detection (chardet) more hints to guess.IOExceptionICodepageDetector.detectCodepage(InputStream, int)public Charset detectCodepage(URL url) throws IOException
Delegates to detectCodepage(InputStream, int)with a buffered input stream of size 10
(8 needed as maximum).
detectCodepage 在接口中 ICodepageDetectordetectCodepage 在类中 AbstractCodepageDetectorCharsetthat represents the
document's codepage.IOException - thrown to indicate that it is was not possible to open the
document specified by the given URL.ICodepageDetector.detectCodepage(URL)Copyright © 2016. All rights reserved.