|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectinfo.monitorenter.cpdetector.io.AbstractCodepageDetector
info.monitorenter.cpdetector.io.CodepageDetectorProxy
public final class CodepageDetectorProxy
A proxy that delegate the codepage detection to all it's delegates. The first
one (added in code-order) that does not return a null Charsetfrom
it's delegate method detectCodepage(URL)wins the race and
determines the codpage of the document specified by the given URL.
If an underlying ICodepageDetectorthrows an
IOException, the delegation search will be terminated by
throwing this exception.
| Method Summary | |
|---|---|
boolean |
add(ICodepageDetector detector)
Adds the given instance to this proxie's detection capability. |
Charset |
detectCodepage(InputStream in,
int length)
Detects the codepage by iteratively delegating the call to all internal ICodepageDetector instances added by
add(ICodepageDetector). |
Charset |
detectCodepage(URL url)
Delegates to ICodepageDetector.detectCodepage(java.io.InputStream, int) with a buffered input stream. |
static CodepageDetectorProxy |
getInstance()
Singleton retrieval method. |
String |
toString()
|
| Methods inherited from class info.monitorenter.cpdetector.io.AbstractCodepageDetector |
|---|
compareTo, open |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static CodepageDetectorProxy getInstance()
Be sure to configure the instance returned at a single location in your code to avoid unpredictable application - wide side effects.
public boolean add(ICodepageDetector detector)
Remember that the order of added ICodepageDetector instances is important for the internal delegation (see class description).
public Charset detectCodepage(URL url)
throws IOException
AbstractCodepageDetectorICodepageDetector.detectCodepage(java.io.InputStream, int) with a buffered input stream.
detectCodepage in interface ICodepageDetectordetectCodepage in class AbstractCodepageDetectorurl - Should link to a file containing textual document. No check for
images or other resources is made.
Charsetthat represents the
document's codepage.
IOException - If a problem with the url - handling occurs.ICodepageDetector.detectCodepage(URL)
public Charset detectCodepage(InputStream in,
int length)
throws IOException,
IllegalArgumentException
Detects the codepage by iteratively delegating the call to all internal
ICodepageDetector instances added by
add(ICodepageDetector).
The given InputStream has to support mark such that the call
InputStream.mark(int) with argument length does not throw an
exception. This is needed, as the stream has to be resetted to the
beginning for each internal delegate that tries to detect.
If this is impossible (large documents), prefer using
detectCodepage(URL).
in - 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 shouls 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.
IllegalArgumentException - if more bytes had to be read from the input stream than param
length or the given input stream does not support marking.
IOExceptioncpdetector.io.ICodepageDetector#detectCodepage(java.io.InputStream,
int length)public String toString()
toString in class ObjectObject.toString()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||