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


Java CharsetDecoder.charset方法代码示例

本文整理汇总了Java中java.nio.charset.CharsetDecoder.charset方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetDecoder.charset方法的具体用法?Java CharsetDecoder.charset怎么用?Java CharsetDecoder.charset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.charset.CharsetDecoder的用法示例。


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

示例1: checkBig

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
private Def checkBig(FileObject fileObject, File file,
        SearchListener listener) {

    Charset charset = FileEncodingQuery.getEncoding(fileObject);
    CharsetDecoder decoder = prepareDecoder(charset);

    LongCharSequence longSequence = null;
    try {
        longSequence = new LongCharSequence(file, charset);
        List<TextDetail> textDetails = multiline
                ? matchWholeFile(longSequence, fileObject)
                : matchLines(longSequence, fileObject);
        if (textDetails == null) {
            return null;
        } else {
            Def def = new Def(fileObject, decoder.charset(), textDetails);
            return def;
        }
    } catch (Exception ex) {
        listener.generalError(ex);
        return null;
    } finally {
        if (longSequence != null) {
            longSequence.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:FastMatcher.java

示例2: checkMeasuredInternal

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
@Override
protected Def checkMeasuredInternal(FileObject fo,
        SearchListener listener) {

    MappedByteBuffer bb = null;
    FileChannel fc = null;
    try {

        listener.fileContentMatchingStarted(fo.getPath());
        File file = FileUtil.toFile(fo);

        // Open the file and then get a channel from the stream
        FileInputStream fis = new FileInputStream(file);
        fc = fis.getChannel();

        // Get the file's size and then map it into memory
        int sz = (int) fc.size();
        bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);

        //  if (asciiPattern && !matchesIgnoringEncoding(bb)) {
        //    return null;
        //}

        // Decode the file into a char buffer
        Charset charset = FileEncodingQuery.getEncoding(fo);
        CharsetDecoder decoder = prepareDecoder(charset);
        decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
        CharBuffer cb = decoder.decode(bb);

        List<TextDetail> textDetails = matchWholeFile(cb, fo);

        if (textDetails == null) {
            return null;
        } else {
            Def def = new Def(fo, decoder.charset(), textDetails);
            return def;
        }
    } catch (Exception e) {
        listener.generalError(e);
        return null;
    } finally {
        if (fc != null) {
            try {
                fc.close();
            } catch (IOException ex) {
                listener.generalError(ex);
            }
        }
        MatcherUtils.unmap(bb);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:MultiLineMappedMatcherSmall.java

示例3: checkSmall

import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
/**
 * Check file content using Java NIO API.
 */
private Def checkSmall(FileObject fo, File file,
        SearchListener listener) {

    MappedByteBuffer bb = null;
    FileChannel fc = null;
    try {
        // Open the file and then get a channel from the stream
        FileInputStream fis = new FileInputStream(file);
        fc = fis.getChannel();

        // Get the file's size and then map it into memory
        int sz = (int) fc.size();
        bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);

        if (asciiPattern && !matchesIgnoringEncoding(bb)) {
            return null;
        }
        // Decode the file into a char buffer
        Charset charset = FileEncodingQuery.getEncoding(fo);
        CharsetDecoder decoder = prepareDecoder(charset);
        decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
        CharBuffer cb = decoder.decode(bb);

        List<TextDetail> textDetails = multiline
                ? matchWholeFile(cb, fo)
                : matchLines(cb, fo);
        if (textDetails == null) {
            return null;
        } else {
            Def def = new Def(fo, decoder.charset(), textDetails);
            return def;
        }
    } catch (Exception e) {
        listener.generalError(e);
        return null;
    } finally {
        if (fc != null) {
            try {
                fc.close();
            } catch (IOException ex) {
                listener.generalError(ex);
            }
        }
        unmap(bb);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:FastMatcher.java


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