当前位置: 首页>>代码示例>>Java>>正文


Java CodepageDetectorProxy类代码示例

本文整理汇总了Java中info.monitorenter.cpdetector.io.CodepageDetectorProxy的典型用法代码示例。如果您正苦于以下问题:Java CodepageDetectorProxy类的具体用法?Java CodepageDetectorProxy怎么用?Java CodepageDetectorProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodepageDetectorProxy类属于info.monitorenter.cpdetector.io包,在下文中一共展示了CodepageDetectorProxy类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileEncode

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
/**
 * 获取文件编码格式
 * 需要包antlr.jar cpdetector.jar chardet.jar
 * @param file
 * @return
 */
public static String getFileEncode(File file){
	String encode = "UTF-8";

	Charset charset = null;
	try {
		CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
	//	detector.add(JChardetFacade.getInstance());
		charset = detector.detectCodepage(file.toURI().toURL());
	} catch (Exception e) {
		e.printStackTrace();
	}
	if (charset != null) {
		encode = charset.name();
	}

	return encode;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:24,代码来源:FileUtil.java

示例2: detectFileEncoding

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
public static String detectFileEncoding(File f) {
	CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
	
	detector.add(UnicodeDetector.getInstance());
	detector.add(ASCIIDetector.getInstance());
	detector.add(new ParsingDetector(false));
	detector.add(JChardetFacade.getInstance());
	java.nio.charset.Charset charset = null;
	try {
		charset = detector.detectCodepage(f.toURI().toURL());
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	if (charset != null)
		return charset.name();
	else
		return null;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:19,代码来源:FileEncodingDetector.java

示例3: getEncodeByUtil

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
/**
     * 使用工具获取文件的编码方式
     *
     * @param file
     * @return
     */
    public static synchronized String getEncodeByUtil(File file) {
        CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();

        detector.add(new ParsingDetector(false));

        detector.add(JChardetFacade.getInstance());// 用到antlr.jar、chardet.jar
        // ASCIIDetector用于ASCII编码测定
        detector.add(ASCIIDetector.getInstance());
        // UnicodeDetector用于Unicode家族编码的测定
//        detector.add(UnicodeDetector.getInstance());
        Charset charset = null;
        try {
            charset = detector.detectCodepage(file.toURI().toURL());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (charset != null)
            return charset.name();
        else
            return null;
    }
 
开发者ID:blademainer,项目名称:common_utils,代码行数:28,代码来源:FileEncode.java

示例4: detectFileEncoding

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
public static String detectFileEncoding(File f) {
	CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
	
	detector.add(UnicodeDetector.getInstance());
	detector.add(ASCIIDetector.getInstance());
	detector.add(new ParsingDetector(false));
	detector.add(JChardetFacade.getInstance());
	java.nio.charset.Charset charset = null;
	try {
		charset = detector.detectCodepage(f.toURI().toURL());
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	if (charset != null){
		// 因为 utf-8 兼容 US-ASCII,但 US-ASCII 不兼容 UTF-8,对中文等亚州语系无法兼容。故应变成 UTF-8
		if (charset.name().equalsIgnoreCase("US-ASCII")) {
			return "UTF-8";
		}
		return charset.name();
	}else{
		return null;
	}
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:24,代码来源:FileEncodingDetector.java

示例5: getFileCharset

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
/**
 * 获取某个文本文件所采用的字符集
 * @author Administrator
 * @param file
 * @return
 */
@SuppressWarnings("deprecation")
public static String getFileCharset(File file)
{
    if (file == null || !file.exists())
    {
        return null;
    }
    CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
    detector.add(new ParsingDetector(false));
    detector.add(JChardetFacade.getInstance());
    detector.add(ASCIIDetector.getInstance());
    detector.add(UnicodeDetector.getInstance());
    Charset charset = null;
    try
    {
        charset = detector.detectCodepage(file.toURL());
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
    if (charset != null)
    {
        return charset.name();
    }
    return null;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:34,代码来源:CharsetKit.java

示例6: getFileEncode

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
/** 利用第三方开源包cpdetector获取文件编码格式
 * 
 * @param path
 *            要判断文件编码格式的源文件的路径
 * @author huanglei
 * @version 2012-7-12 14:05 */
public static String getFileEncode(File f) {
	/*
	 * detector是探测器,它把探测任务交给具体的探测实现类的实例完成。
	 * cpDetector内置了一些常用的探测实现类,这些探测实现类的实例可以通过add方法 加进来,如ParsingDetector、
	 * JChardetFacade、ASCIIDetector、UnicodeDetector。
	 * detector按照“谁最先返回非空的探测结果,就以该结果为准”的原则返回探测到的
	 * 字符集编码。使用需要用到三个第三方JAR包:antlr.jar、chardet.jar和cpdetector.jar
	 * cpDetector是基于统计学原理的,不保证完全正确。
	 */
	CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
	/*
	 * ParsingDetector可用于检查HTML、XML等文件或字符流的编码,构造方法中的参数用于
	 * 指示是否显示探测过程的详细信息,为false不显示。
	 */
	detector.add(new ParsingDetector(false));
	/*
	 * JChardetFacade封装了由Mozilla组织提供的JChardet,它可以完成大多数文件的编码
	 * 测定。所以,一般有了这个探测器就可满足大多数项目的要求,如果你还不放心,可以
	 * 再多加几个探测器,比如下面的ASCIIDetector、UnicodeDetector等。
	 */
	detector.add(JChardetFacade.getInstance());// 用到antlr.jar、chardet.jar
	// ASCIIDetector用于ASCII编码测定
	detector.add(ASCIIDetector.getInstance());
	// UnicodeDetector用于Unicode家族编码的测定
	detector.add(UnicodeDetector.getInstance());
	java.nio.charset.Charset charset = null;
	try {
		charset = detector.detectCodepage(f.toURI().toURL());
	}
	catch (Exception ex) {
		ex.printStackTrace();
	}
	if (charset != null)
		return charset.name();
	else
		return null;
}
 
开发者ID:niaoge,项目名称:spring-dynamic,代码行数:44,代码来源:FileUtils.java

示例7: CodepageProcessor

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
public CodepageProcessor() {
  super();
  this.detector = CodepageDetectorProxy.getInstance();
  // adding the options:
  this.addCmdLineOption("documents", new CmdLineParser.Option.StringOption('r', "documents"));
  this.addCmdLineOption("extensions", new CmdLineParser.Option.StringOption('e', "extensions"));
  this.addCmdLineOption("outputDir", new CmdLineParser.Option.StringOption('o', "outputDir"));
  this.addCmdLineOption("moveUnknown", new CmdLineParser.Option.BooleanOption('m', "moveUnknown"));
  this.addCmdLineOption("verbose", new CmdLineParser.Option.BooleanOption('v', "verbose"));
  this.addCmdLineOption("wait", new CmdLineParser.Option.IntegerOption('w', "wait"));
  this.addCmdLineOption("transform", new CmdLineParser.Option.StringOption('t', "transform"));
  this.addCmdLineOption("detectors", new CmdLineParser.Option.StringOption('d', "detectors"));
  this.addCmdLineOption("charsets", new CmdLineParser.Option.BooleanOption('c', "charsets"));
}
 
开发者ID:blademainer,项目名称:common_utils,代码行数:15,代码来源:CodepageProcessor.java

示例8: getFileCode

import info.monitorenter.cpdetector.io.CodepageDetectorProxy; //导入依赖的package包/类
/** 
 * @param args 
 */  
public static Charset getFileCode(File f) {  
    /*------------------------------------------------------------------------  
 
 
      detector是探测器,它把探测任务交给具体的探测实现类的实例完成。  
 
      cpDetector内置了一些常用的探测实现类,这些探测实现类的实例可以通过add方法  
 
      加进来,如ParsingDetector、 JChardetFacade、ASCIIDetector、UnicodeDetector。    
 
      detector按照“谁最先返回非空的探测结果,就以该结果为准”的原则返回探测到的  
 
      字符集编码。  
 
    --------------------------------------------------------------------------*/  
  
    CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();  
  
    /*-------------------------------------------------------------------------  
 
      ParsingDetector可用于检查HTML、XML等文件或字符流的编码,构造方法中的参数用于  
 
      指示是否显示探测过程的详细信息,为false不显示。  
 
    ---------------------------------------------------------------------------*/  
  
    detector.add(new ParsingDetector(false));//如果不希望判断xml的encoding,而是要判断该xml文件的编码,则可以注释掉  
  
    /*--------------------------------------------------------------------------  
 
       JChardetFacade封装了由Mozilla组织提供的JChardet,它可以完成大多数文件的编码  
 
       测定。所以,一般有了这个探测器就可满足大多数项目的要求,如果你还不放心,可以  
 
       再多加几个探测器,比如下面的ASCIIDetector、UnicodeDetector等。  
 
      ---------------------------------------------------------------------------*/  
  
    detector.add(JChardetFacade.getInstance());  
  
    // ASCIIDetector用于ASCII编码测定  
  
    detector.add(ASCIIDetector.getInstance());  
  
    // UnicodeDetector用于Unicode家族编码的测定  
  
    detector.add(UnicodeDetector.getInstance());  
  
    Charset charset = null;  
  
    try {  
  
        charset = detector.detectCodepage(f.toURL());  
  
    } catch (Exception ex) {  
        ex.printStackTrace();  
    }  
  
    if (charset != null) {  
  
        System.out.println(f.getName() + "编码是:" + charset.name());  
  
    } else {  
  
        System.out.println(f.getName() + "未知");  
    }  
    return charset;
  
}
 
开发者ID:luhaoaimama1,项目名称:JavaZone,代码行数:73,代码来源:JudgeFileCode.java


注:本文中的info.monitorenter.cpdetector.io.CodepageDetectorProxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。