return;
}
//Initialize the nsDetector();
int lang = (argv.length == 2) ? Integer.parseInt(argv[1]) : PSMDetector.ALL;
Detector det = new Detector(lang);
//Set an observer...
//The Notify() will be called when a matching charset is found.
det.init(new ICharsetDetectionObserver()
{
public void notify(String charset)
{
HtmlCharsetDetector.found = true;
System.out.println("CHARSET = " + charset);
}
});
URL url = new URL(argv[0]);
BufferedInputStream imp = new BufferedInputStream(url.openStream());
byte[] buf = new byte[1024];
int len;
boolean done = false;
boolean isAscii = true;
while ((len = imp.read(buf, 0, buf.length)) != -1)
{
//Check if the stream is only ascii.
if (isAscii)
isAscii = det.isAscii(buf, len);
//DoIt if non-ascii and not done yet.
if (!isAscii && !done)
done = det.doIt(buf, len, false);
}
det.dataEnd();
if (isAscii)
{
System.out.println("CHARSET = ARSII");
found = true;
}
if (!found)
{
String prob[] = det.getProbableCharsets();
for (int i = 0; i < prob.length; i++)
{
System.out.println("Probable Charset = " + prob[i]);
}
}