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


Java SourceReader类代码示例

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


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

示例1: readSource

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true, 
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:18,代码来源:Main.java

示例2: getScope

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
static Scriptable getScope(String path) {
    if (useRequire) {
        // If CommonJS modules are enabled use a module scope that resolves
        // relative ids relative to the current URL, file or working directory.
        URI uri;
        if (path == null) {
            // use current directory for shell and -e switch
            uri = new File(System.getProperty("user.dir")).toURI();
        } else {
            // find out whether this is a file path or a URL
            if (SourceReader.toUrl(path) != null) {
                try {
                    uri = new URI(path);
                } catch (URISyntaxException x) {
                    // fall back to file uri
                    uri = new File(path).toURI();
                }
            } else {
                uri = new File(path).toURI();
            }
        }
        return new ModuleScope(global, uri, null);
    } else {
        return global;
    }
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:27,代码来源:Main.java

示例3: readSource

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
private String readSource(File f)
{
    String absPath = f.getAbsolutePath();
    if (!f.isFile()) {
        addError("msg.jsfile.not.found", absPath);
        return null;
    }
    try {
        return (String)SourceReader.readFileOrUrl(absPath, true,
                characterEncoding);
    } catch (FileNotFoundException ex) {
        addError("msg.couldnt.open", absPath);
    } catch (IOException ioe) {
        addFormatedError(ioe.toString());
    }
    return null;
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:18,代码来源:Main.java

示例4: readFileOrUrl

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
{
    try {
        return SourceReader.readFileOrUrl(path, convertToString, 
                shellContextFactory.getCharacterEncoding());
    } catch (IOException ex) {
        Context.reportError(ToolErrorReporter.getMessage(
                "msg.couldnt.read.source", path, ex.getMessage()));
        return null;
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:Main.java

示例5: test262SuiteValues

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
@Parameters(name = "js={0}, opt={3}, strict={4}")
public static Collection<Object[]> test262SuiteValues() throws IOException {
    List<Object[]> result = new ArrayList<Object[]>();
    List<File> tests = getTestFiles();
    for (File jsTest : tests) {
        String jsFileStr = (String) SourceReader.readFileOrUrl(jsTest.getPath(), true, "UTF-8");
        List<String> harnessFiles = new ArrayList<String>();
        harnessFiles.add("sta.js");
        harnessFiles.add("assert.js");

        Map header = (Map) YAML.load(jsFileStr.substring(jsFileStr.indexOf("/*---") + 5, jsFileStr.lastIndexOf("---*/")));
        if (header.containsKey("includes")) {
            harnessFiles.addAll((Collection)header.get("includes"));
        }

        EcmaErrorType errorType = EcmaErrorType._valueOf((String)header.get("negative"));
        List<String> flags = header.containsKey("flags") ? (List<String>) header.get("flags") : Collections.EMPTY_LIST;
        for (int optLevel : OPT_LEVELS) {
            if (!flags.contains("onlyStrict")) {
                result.add(new Object[]{jsTest.getPath(), jsFileStr, harnessFiles, optLevel, false, errorType});
            }
            if (!flags.contains("noStrict")) {
                result.add(new Object[]{jsTest.getPath(), jsFileStr, harnessFiles, optLevel, true, errorType});
            }
        }
    }
    return result;
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:29,代码来源:Test262SuiteTest.java

示例6: readFileOrUrl

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
/**
 * Read file or url specified by <tt>path</tt>.
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException
{
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:12,代码来源:Main.java

示例7: readFileOrUrl

import org.mozilla.javascript.tools.SourceReader; //导入依赖的package包/类
/**
 * Read file or url specified by <tt>path</tt>.
 *
 * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
 * <tt>convertToString</tt> is true.
 */
private static Object readFileOrUrl(String path, boolean convertToString)
        throws IOException {
    return SourceReader.readFileOrUrl(path, convertToString,
            shellContextFactory.getCharacterEncoding());
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:12,代码来源:Main.java


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