• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FileEncodingQuery类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: checkMeasuredInternal

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
protected Def checkMeasuredInternal(FileObject file,
        SearchListener listener) {

    Charset charset = FileEncodingQuery.getEncoding(file);

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


示例2: testRead

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public void testRead() throws IOException {

        MockServices.setServices(Utf8FileEncodingQueryImpl.class);

        FileObject dir = FileUtil.toFileObject(getDataDir());
        assertNotNull(dir);
        FileObject file = dir.getFileObject(
                "textFiles/utf8file.txt");
        Charset c = FileEncodingQuery.getEncoding(file);
        MatchingObject mo = new MatchingObject(new ResultModel(
                new BasicSearchCriteria(), "", null), file, c, null);
        StringBuilder text = mo.text(true);
        String textStr = text.toString();
        int lineBreakSize = textStr.charAt(textStr.length() - 1) == '\n'
                && textStr.charAt(textStr.length() - 2) == '\r' ? 2 : 1;
        assertEquals('.', textStr.charAt(textStr.length() - lineBreakSize - 1));
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:MatchingObjectTest.java


示例3: getProjectEncoding

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
/**
 * Get the encoding of the supplied project as a Charset object
 * @param project The project
 * @param file A file in the project
 * @return The project encoding, or a suitable default if the project encoding cannot be determined. Never null
 */
public static Charset getProjectEncoding(Project project, FileObject file) {
    Charset encoding = project.getLookup().lookup(FileEncodingQueryImplementation.class).getEncoding(file);
    if (encoding == null) {
        encoding = FileEncodingQuery.getDefaultEncoding();
        if (encoding == null) {
            return Charset.forName("UTF-8");
        }
        else {
            return encoding;
        }
    }
    else {
        return encoding;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JpaControllerUtil.java


示例4: getProjectEncodingAsString

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
/**
 * Get the encoding of the supplied project as a String (by performing a lookup and invoking Charset.name).
 * @param project The project
 * @param file A file in the project
 * @return The project encoding, or a suitable default if the project encoding cannot be determined. Never null
 */
public static String getProjectEncodingAsString(Project project, FileObject file) {
    Charset encoding = project.getLookup().lookup(FileEncodingQueryImplementation.class).getEncoding(file);
    if (encoding == null) {
        encoding = FileEncodingQuery.getDefaultEncoding();
        if (encoding == null) {
            return "UTF-8";
        }
        else {
            return encoding.name();
        }
    }
    else {
        return encoding.name();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JpaControllerUtil.java


示例5: createFromTemplate

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
public FileObject createFromTemplate(FileObject template,
                                        FileObject targetFolder,
                                        String name,
                                        Map<String, Object> parameters) throws IOException {
    String nameUniq = FileUtil.findFreeFileName(targetFolder, name, template.getExt());
    FileObject newFile = FileUtil.createData(targetFolder, nameUniq + '.' + template.getExt());

    Charset templateEnc = FileEncodingQuery.getEncoding(template);
    Charset newFileEnc = FileEncodingQuery.getEncoding(newFile);

    InputStream is = template.getInputStream();
    Reader reader = new BufferedReader(new InputStreamReader(is, templateEnc));
    OutputStream os = newFile.getOutputStream();
    Writer writer = new BufferedWriter(new OutputStreamWriter(os, newFileEnc));
    int cInt;
    while ((cInt = reader.read()) != -1) {
        writer.write(cInt);
    }
    writer.close();
    reader.close();

    return newFile;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Bug138973Test.java


示例6: testCreateFromTemplateEncodingProperty

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public void testCreateFromTemplateEncodingProperty() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    os.write("print(encoding)".getBytes());
    os.close();
    assertEquals("content/unknown", fo.getMIMEType());
    fo.setAttribute ("template", Boolean.TRUE);
    assertEquals("content/unknown", fo.getMIMEType());
    fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
    
    DataObject obj = DataObject.find(fo);
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    
    Map<String,String> parameters = Collections.emptyMap();
    DataObject inst = obj.createFromTemplate(folder, "complex", parameters);
    FileObject instFO = inst.getPrimaryFile();
    
    Charset targetEnc = FileEncodingQuery.getEncoding(instFO);
    assertNotNull("Template encoding is null", targetEnc);
    String instText = stripNewLines(instFO.asText());
    assertEquals("Encoding in template doesn't match", targetEnc.name(), instText);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ScriptingCreateFromTemplateTest.java


示例7: close

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public synchronized @Override void close() throws IOException {
    try {
        LineDocumentUtils.as(doc, AtomicLockDocument.class).runAtomic(new Runnable () {
                @Override
                public void run () {
                    try {
                        doc.remove(0,doc.getLength());
                        doc.insertString(0,new String(
                            data,
                            0,
                            pos,
                            FileEncodingQuery.getEncoding(getHandle().resolveFileObject(false))),
                        null);
                    } catch (BadLocationException e) {
                        if (LOG.isLoggable(Level.SEVERE))
                            LOG.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            });
    } finally {
        resetCaches();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BasicSourceFileObject.java


示例8: parsePackage

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@NonNull
private static String parsePackage(FileObject file) {
    String pkg = "";    //NOI18N
        final JavacTaskImpl jt = JavacParser.createJavacTask(
                new ClasspathInfo.Builder(ClassPath.EMPTY).build(),
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                Collections.singletonList(FileObjects.fileObjectFileObject(
                file,
                file.getParent(),
                null,
                FileEncodingQuery.getEncoding(file))));
        final CompilationUnitTree cu =  jt.parse().iterator().next();
        pkg = Optional.ofNullable(cu.getPackage())
                .map((pt) -> pt.getPackageName())
                .map((xt) -> xt.toString())
                .orElse(pkg);
    return pkg;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ModuleOraculum.java


示例9: loadFromStreamToKit

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
    if (guardedEditor == null) {
        guardedEditor = new FormGEditor();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find("text/x-java");
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }

    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:GuardedBlockTest.java


示例10: MergeResultWriterInfo

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public MergeResultWriterInfo(File tempf1, File tempf2, File tempf3,
                             File outputFile, String mimeType,
                             String leftFileRevision, String rightFileRevision,
                             FileObject fo, FileLock lock, Charset encoding,
                             String newLineString) {
    this.tempf1 = tempf1;
    this.tempf2 = tempf2;
    this.tempf3 = tempf3;
    this.outputFile = outputFile;
    this.mimeType = mimeType;
    this.leftFileRevision = leftFileRevision;
    this.rightFileRevision = rightFileRevision;
    this.fo = fo;
    this.lock = lock;
    this.newLineString = newLineString;
    if (encoding == null) {
        encoding = FileEncodingQuery.getEncoding(FileUtil.toFileObject(tempf1));
    }
    this.encoding = encoding;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ResolveConflictsExecutor.java


示例11: associateEncoding

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
/**
 * Retrieves the Charset for the referenceFile and associates it weakly with
 * the given file. A following getAssociatedEncoding() call for
 * the file will then return the referenceFile-s Charset.
 *
 * @param referenceFile the file which charset has to be used when encoding file
 * @param file file to be encoded with the referenceFile-s charset
 *
 */
public static void associateEncoding(File referenceFile, File file) {
    FileObject refFO = FileUtil.toFileObject(referenceFile);
    if (refFO == null || refFO.isFolder()) {
        return;
    }
    FileObject fo = FileUtil.toFileObject(file);
    if (fo == null || fo.isFolder()) {
        return;
    }
    Charset c = FileEncodingQuery.getEncoding(refFO);
    if (c != null) {
        synchronized(ENCODING_LOCK) {
            if (fileToFileObject == null) {
                fileToFileObject = new WeakHashMap<File, FileObject>();
            }
            fileToFileObject.put(file, fo);
        }
        associateEncoding(fo, c);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:Utils.java


示例12: loadFromStreamToKit

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit)
        throws IOException, BadLocationException {
    
    if (guardedEditor == null) {
        guardedEditor = new BIGES();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find(((DataEditorSupport.Env) env).getMimeType());
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }
    
    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:BIEditorSupport.java


示例13: saveFromKitToStream

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream)
        throws IOException, BadLocationException {
    
    if (guardedProvider != null) {
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Writer writer = guardedProvider.createGuardedWriter(stream, c);
        try {
            kit.write(writer, doc, 0, doc.getLength());
        } finally {
            writer.close();
        }
    } else {
        super.saveFromKitToStream(doc, kit, stream);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:BIEditorSupport.java


示例14: openDocument

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
public StyledDocument openDocument() throws IOException {
    DataObject tmpObj = getDataObject();
    Charset c = charsets.get(tmpObj);
    if (c == null) {
        c = FileEncodingQuery.getEncoding(tmpObj.getPrimaryFile());
    }
    try {
        charsets.put(tmpObj, c);
        incrementCacheCounter(tmpObj);
        return super.openDocument();
    } finally {
        if (decrementCacheCounter(tmpObj) == 0) {
            charsets.remove(tmpObj);
        }
        ERR.finest("openDocument - charset removed");
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:DataEditorSupport.java


示例15: copyFile

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
private void copyFile (final FileObject from, final FileObject to) throws IOException {        
    final Charset ci = FileEncodingQuery.getEncoding(from);
    final Reader in = new BufferedReader (new InputStreamReader (from.getInputStream(),ci));
    try {
        final FileLock lck = to.lock();
        try {
            final Charset co = FileEncodingQuery.getEncoding(to);
            final Writer out = new BufferedWriter (new OutputStreamWriter (to.getOutputStream(lck),co));
            try {
                final char[] data = new char[1024];
                int len;
                while ((len=in.read(data, 0, data.length))>0) {
                    out.write(data, 0, len);
                }
            } finally {
                out.close();
            }
        } finally {
            lck.releaseLock();
        }
    } finally {
        in.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:XmlFileEncodingQueryImplTest.java


示例16: testCreateFromTemplateEncodingProperty

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public void testCreateFromTemplateEncodingProperty() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    os.write("${encoding}".getBytes());
    os.close();
    assertEquals("content/unknown", fo.getMIMEType());
    fo.setAttribute ("template", Boolean.TRUE);
    assertEquals("content/unknown", fo.getMIMEType());
    fo.setAttribute("javax.script.ScriptEngine", "freemarker");
    assertEquals("text/x-freemarker", fo.getMIMEType());
    
    DataObject obj = DataObject.find(fo);
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    
    Map<String,String> parameters = Collections.emptyMap();
    DataObject inst = obj.createFromTemplate(folder, "complex", parameters);
    FileObject instFO = inst.getPrimaryFile();
    
    Charset targetEnc = FileEncodingQuery.getEncoding(instFO);
    assertNotNull("Template encoding is null", targetEnc);
    assertEquals("Encoding in template doesn't match", targetEnc.name(), instFO.asText());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ScriptingCreateFromTemplateTest.java


示例17: testFileEncodingQuery

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public void testFileEncodingQuery () throws Exception {
    final Charset UTF8 = Charset.forName("UTF-8");
    final Charset ISO15 = Charset.forName("ISO-8859-15");
    final Charset CP1252 = Charset.forName("CP1252");
    FileObject java = sources.createData("a.java");
    Charset enc = FileEncodingQuery.getEncoding(java);
    assertEquals(UTF8,enc);
    FileObject xml = sources.createData("b.xml");
    enc = FileEncodingQuery.getEncoding(xml);
    assertEquals(ISO15,enc);
    ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
        public Void run() throws Exception {
            EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
            ep.setProperty(ProjectProperties.SOURCE_ENCODING, CP1252.name());
            helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
            ProjectManager.getDefault().saveProject(prj);
            return null;
        }
    });
    enc = FileEncodingQuery.getEncoding(java);
    assertEquals(CP1252,enc);
    FileObject standAloneJava = scratch.createData("b.java");
    enc = FileEncodingQuery.getEncoding(standAloneJava);
    assertEquals(Charset.defaultCharset(), enc);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:FileEncodingQueryTest.java


示例18: close

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public synchronized @Override void close() throws IOException {
    try {
        NbDocument.runAtomic(this.doc,
            new Runnable () {
                @Override
                public void run () {
                    try {
                        doc.remove(0,doc.getLength());
                        doc.insertString(0,new String(
                            data,
                            0,
                            pos,
                            FileEncodingQuery.getEncoding(getHandle().resolveFileObject(false))),
                        null);
                    } catch (BadLocationException e) {
                        if (LOG.isLoggable(Level.SEVERE))
                            LOG.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            });
    } finally {
        resetCaches();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SourceFileObject.java


示例19: loadFromStreamToKit

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
    if (guardedEditor == null) {
        guardedEditor = new FormGEditor();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find(((DataEditorSupport.Env) env).getMimeType());
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }
    
    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:FormEditorSupport.java


示例20: expandTemplate

import org.netbeans.api.queries.FileEncodingQuery; //导入依赖的package包/类
public static void expandTemplate(InputStream template, FileObject toFile, Map<String, Object> values) throws IOException {
    Charset targetEncoding = FileEncodingQuery.getEncoding(toFile);
    if(toFile.isLocked()){
        LOG.log(Level.SEVERE, "File {0} is locked", new Object[]{toFile.getName()});
        return;
    }
    FileLock lock = toFile.lock();
    try (Writer writer = new OutputStreamWriter(toFile.getOutputStream(lock), targetEncoding)) {
        expandTemplate(new InputStreamReader(template), writer, values, targetEncoding);
    } finally {
        lock.releaseLock();
    }
    DataObject dob = DataObject.find(toFile);
    if (dob != null) {
        reformat(dob);
    }
}
 
开发者ID:jeddict,项目名称:jCode,代码行数:18,代码来源:FileUtil.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EnumOutline类代码示例发布时间:2022-05-23
下一篇:
Java QueryHints类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap