Examples of nsDetector


Examples of org.mozilla.intl.chardet.nsDetector

        // we could do things like make buttons visible and invisible here
    }

    private String getCharset(String contentType, byte[] bytes) {
        String[] charsets;
        nsDetector det = new nsDetector(nsPSMDetector.ALL);
       
        boolean isAscii = det.isAscii(bytes,bytes.length);
        // DoIt if non-ascii and not done yet.
        if (!isAscii)
            det.DoIt(bytes,bytes.length, false);
        charsets = det.getProbableCharsets();
        det.DataEnd();
       
        if (isAscii) return "ASCII";
        if (charsets.length == 0) return null;
        if (charsets.length == 1 && charsets[0].equals("nomatch")) return null;
       
View Full Code Here

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

Examples of org.mozilla.intl.chardet.nsDetector

    } 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

Examples of org.vietspider.chars.jchardet.nsDetector

public class EncodingDetector {
 
  protected String charset_;
 
  public String detect(byte [] buf){
    nsDetector det = new nsDetector(nsPSMDetector.ALL) ;
    charset_ = null;
    det.Init(new nsICharsetDetectionObserver() {
      @Override
      public void Notify(String charset) {
        charset_ = charset;
       
      }
    });

    boolean isAscii = true ;
    int len = buf.length;
   
    isAscii = det.isAscii(buf, len);  
    if (!isAscii) det.DoIt(buf, len, false);
    det.DataEnd();
   
    if (isAscii) charset_ = "ASCII";
    return charset_;
  }
View Full Code Here

Examples of org.vietspider.chars.jchardet.nsDetector

    return createDocument(reader.load(file), charset);
 

  @Deprecated()
  public static String detect(byte [] buf){
    nsDetector det = new nsDetector(nsPSMDetector.ALL) ;
    charset_ = null;
    det.Init(new nsICharsetDetectionObserver() {
      @Override
      public void Notify(String charset) {
        charset_ = charset;
       
      }
    });

    boolean isAscii = true ;
    int len = buf.length;
   
    isAscii = det.isAscii(buf, len);  
    if (!isAscii) det.DoIt(buf, len, false);
    det.DataEnd();
   
    if (isAscii) charset_ = "ASCII";
    return charset_;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.