Package org.mozilla.intl.chardet

Examples of org.mozilla.intl.chardet.nsDetector


        this.source = source;
        this.length = length;
    }
   
    public Encoding sniff() throws IOException {
        nsDetector detector = new nsDetector(nsPSMDetector.ALL);
        detector.Init(this);
        detector.DoIt(source, length, false);
        detector.DataEnd();
        if (returnValue != null && returnValue != Encoding.WINDOWS1252 && returnValue.isAsciiSuperset()) {
            return returnValue;
        } else {
            return null;
        }
View Full Code Here


    } else if (hasUtf1BOM(buf, len)) {
      charset = UTF1;
      buffered.write(buf, 3, len - 3);
    } else {
      // Use jchardet which tries a variety of heuristics to choose an encoding.
      nsDetector det = new nsDetector(nsPSMDetector.ALL);
      class Observer implements nsICharsetDetectionObserver {
        String charset;
        public void Notify(String charset) {
          this.charset = charset;
        }
      }
      // The below is adapted from the main method in HtmlCharsetDetector.
      Observer observer = new Observer();
      det.Init(observer);
      do {
        buffered.write(buf, 0, len);
        if (isAscii) { isAscii = det.isAscii(buf, len); }
        if (!isAscii) {
          if (det.DoIt(buf, len, false)) { break; }
        }
      } while ((len = in.read(buf)) > 0);
      det.DataEnd();
      charset = observer.charset;
    }
    if (charset != null) { charset = supportedCharsetName(charset); }
    if (charset == null) { charset = UTF8; }
    return Pair.pair(
View Full Code Here

TOP

Related Classes of org.mozilla.intl.chardet.nsDetector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.