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


Java URLReader类代码示例

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


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

示例1: testSlowScope

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
/**
 * Test "slow" scopes involving {@code with} and {@code eval} statements for shared script classes with multiple globals.
 * @throws ScriptException
 * @throws InterruptedException
 */
@Test
public static void testSlowScope() throws ScriptException, InterruptedException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");

    for (int i = 0; i < 100; i++) {
        final Bindings b = e.createBindings();
        final ScriptContext ctxt = new SimpleScriptContext();
        ctxt.setBindings(b, ScriptContext.ENGINE_SCOPE);

        e.eval(new URLReader(ScopeTest.class.getResource("resources/witheval.js")), ctxt);
        assertEquals(e.eval("a", ctxt), 1);
        assertEquals(b.get("a"), 1);
        assertEquals(e.eval("b", ctxt), 3);
        assertEquals(b.get("b"), 3);
        assertEquals(e.eval("c", ctxt), 10);
        assertEquals(b.get("c"), 10);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ScopeTest.java

示例2: runExternalJsTest

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
public void runExternalJsTest() {
    final String[] paths = new String[]{
            "test/script/basic/compile-octane.js",
            "test/script/basic/jquery.js",
            "test/script/basic/prototype.js",
            "test/script/basic/runsunspider.js",
            "test/script/basic/underscore.js",
            "test/script/basic/yui.js",
            "test/script/basic/run-octane.js"
    };
    final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    for (final String path : paths) {
        final ScriptEngine engine = factory.getScriptEngine(new String[]{"-scripting"}, getClass().getClassLoader(), getClassFilter());
        try {
            engine.eval(new URLReader(new File(path).toURI().toURL()));
        } catch (final Exception e) {
            fail("Script " + path + " fails with exception :" + e.getMessage());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ClassFilterTest.java

示例3: initSpaceGlobal

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
/**
 * Public only for tests
 */
public void initSpaceGlobal() {
    Bindings bindings = SCRIPT_ENGINE.createBindings();
    scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
    try {
        setSpace(Space.this);
        try {
            scriptContext.setAttribute(ScriptEngine.FILENAME, INTERNALS_MODULENAME, ScriptContext.ENGINE_SCOPE);
            SCRIPT_ENGINE.eval(new URLReader(internalsUrl), scriptContext);
        } finally {
            setSpace(null);
        }
    } catch (ScriptException ex) {
        Logger.getLogger(Scripts.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:19,代码来源:Scripts.java

示例4: multiThreadedFunctionTest

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
/**
 * Test multi-threaded scope function invocation for shared script classes with multiple globals.
 */
@Test
public static void multiThreadedFunctionTest() throws ScriptException, InterruptedException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final Bindings b = e.createBindings();
    final ScriptContext origContext = e.getContext();
    final ScriptContext newCtxt = new SimpleScriptContext();
    newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);

    e.eval(new URLReader(ScopeTest.class.getResource("resources/func.js")), origContext);
    assertEquals(origContext.getAttribute("scopeVar"), 1);
    assertEquals(e.eval("scopeTest()"), 1);

    e.eval(new URLReader(ScopeTest.class.getResource("resources/func.js")), newCtxt);
    assertEquals(newCtxt.getAttribute("scopeVar"), 1);
    assertEquals(e.eval("scopeTest();", newCtxt), 1);

    assertEquals(e.eval("scopeVar = 3;", newCtxt), 3);
    assertEquals(newCtxt.getAttribute("scopeVar"), 3);


    final Thread t1 = new Thread(new ScriptRunner(e, origContext, "scopeTest()", 1, 1000));
    final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, "scopeTest()", 3, 1000));

    t1.start();
    t2.start();
    t1.join();
    t2.join();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:ScopeTest.java

示例5: getterSetterTest

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
/**
 * Test multi-threaded access to global getters and setters for shared script classes with multiple globals.
 */
@Test
public static void getterSetterTest() throws ScriptException, InterruptedException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final Bindings b = e.createBindings();
    final ScriptContext origContext = e.getContext();
    final ScriptContext newCtxt = new SimpleScriptContext();
    newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
    final String sharedScript = "accessor1";

    e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), origContext);
    assertEquals(e.eval("accessor1 = 1;"), 1);
    assertEquals(e.eval(sharedScript), 1);

    e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), newCtxt);
    assertEquals(e.eval("accessor1 = 2;", newCtxt), 2);
    assertEquals(e.eval(sharedScript, newCtxt), 2);


    final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, 1, 1000));
    final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, 2, 1000));

    t1.start();
    t2.start();
    t1.join();
    t2.join();

    assertEquals(e.eval(sharedScript), 1);
    assertEquals(e.eval(sharedScript, newCtxt), 2);
    assertEquals(e.eval("v"), 1);
    assertEquals(e.eval("v", newCtxt), 2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ScopeTest.java

示例6: getterSetter2Test

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
/**
 * Test multi-threaded access to global getters and setters for shared script classes with multiple globals.
 */
@Test
public static void getterSetter2Test() throws ScriptException, InterruptedException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final Bindings b = e.createBindings();
    final ScriptContext origContext = e.getContext();
    final ScriptContext newCtxt = new SimpleScriptContext();
    newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
    final String sharedScript = "accessor2";

    e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), origContext);
    assertEquals(e.eval("accessor2 = 1;"), 1);
    assertEquals(e.eval(sharedScript), 1);

    e.eval(new URLReader(ScopeTest.class.getResource("resources/gettersetter.js")), newCtxt);
    assertEquals(e.eval("accessor2 = 2;", newCtxt), 2);
    assertEquals(e.eval(sharedScript, newCtxt), 2);


    final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, 1, 1000));
    final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, 2, 1000));

    t1.start();
    t2.start();
    t1.join();
    t2.join();

    assertEquals(e.eval(sharedScript), 1);
    assertEquals(e.eval(sharedScript, newCtxt), 2);
    assertEquals(e.eval("x"), 1);
    assertEquals(e.eval("x", newCtxt), 2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:ScopeTest.java

示例7: testURLSource

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
@Test
public void testURLSource() {
    try {
        testSources(sourceFor(SOURCE_NAME, SOURCE_URL), sourceFor(SOURCE_NAME, SOURCE_URL));
        testSources(sourceFor(SOURCE_NAME, SOURCE_URL), sourceFor(SOURCE_NAME, new URLReader(SOURCE_URL)));

    } catch (final IOException e) {
        fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SourceTest.java

示例8: testURLReaderSource

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
@Test
public void testURLReaderSource() {
    try {
        System.err.println(SourceTest.class.getResource(""));
        testSources(sourceFor(SOURCE_NAME, new URLReader(SOURCE_URL)), sourceFor(SOURCE_NAME, new URLReader(SOURCE_URL)));
        testSources(sourceFor(SOURCE_NAME, new URLReader(SOURCE_URL)), sourceFor(SOURCE_NAME, SOURCE_URL));
    } catch (final IOException e) {
        fail(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SourceTest.java

示例9: JavaScriptIntentBehavior

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
public JavaScriptIntentBehavior(URL scriptUrl) {
        engine = new ScriptEngineManager().getEngineByName("nashorn");
        try {
//            final String origScript = IOUtils.toString(scriptUrl, StandardCharsets.UTF_8);
//            final String augmentedScript = "with(new JavaImporter(org.lskk.lumen.reasoner.ux)) {\n"
//                    + origScript + "\n}\n";
            engine.eval(new URLReader(scriptUrl, StandardCharsets.UTF_8));
            invocable = (Invocable) engine;
        } catch (Exception e) {
            throw new ReasonerException(e, "Cannot load behavior %s", scriptUrl);
        }
    }
 
开发者ID:lumenrobot,项目名称:lumen,代码行数:13,代码来源:JavaScriptIntentBehavior.java

示例10: onStateChanged

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
/**
     *
     * @param previous
     * @param current
     * @param locale Specific {@link Locale} that was active during the state change, it's always one of {@link InteractionSession#getActiveLocales()}.
     * @param session Only {@link InteractionSession#getScriptables()} is used.
     * @throws Exception
     */
    @Override
    public void onStateChanged(ActivityState previous, ActivityState current, Locale locale, @Nullable InteractionSession session) throws Exception {
        super.onStateChanged(previous, current, locale, session);
        if (ActivityState.ACTIVE == current) {
            final String scriptPath = "/org/lskk/lumen/reasoner/activity/" + getId() + ".js";
            final URL scriptUrl = Preconditions.checkNotNull(Script.class.getResource(scriptPath),
                    "Cannot find script '%s' file in classpath: %s", getId(), scriptPath);
            final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
            engine.eval(new URLReader(scriptUrl, StandardCharsets.UTF_8));
            final Invocable invocable = (Invocable) engine;

            final Map<String, Object> realScriptables = Optional.ofNullable(session.getScriptables()).orElse(ImmutableMap.of());
            log.debug("{} '{}' provides {} scriptables: {}", getClass().getSimpleName(), getPath(),
                    realScriptables.size(), realScriptables.keySet());
            engine.getBindings(ScriptContext.ENGINE_SCOPE).putAll(realScriptables);

            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("log", log);
//            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("intent", intent);

            final LinkedHashMap<String, Slot> inSlotsVar = new LinkedHashMap<>();
            getInSlots().forEach(slot -> inSlotsVar.put(slot.getId(), slot));
            final LinkedHashMap<String, Slot> outSlotsVar = new LinkedHashMap<>();
            getOutSlots().forEach(slot -> outSlotsVar.put(slot.getId(), slot));
            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("inSlots", inSlotsVar);
            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("outSlots", outSlotsVar);
            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("pendingCommunicateActions", getPendingCommunicateActions());
            invocable.invokeFunction("onActivate");

            // if everything's good, the Script can complete
            session.complete(this, locale);
        }
    }
 
开发者ID:lumenrobot,项目名称:lumen,代码行数:41,代码来源:Script.java

示例11: initialize

import jdk.nashorn.api.scripting.URLReader; //导入依赖的package包/类
@BeforeClass
public static void initialize() throws IOException {
    loadMain();
    EnigmaReader reader
            = new EnigmaReader(new BufferedReader(new URLReader(
                    ClassLoader.getSystemResource("mappings/example.eng"))));
    helper = new ReaderTestHelper(reader.read());
}
 
开发者ID:LapisBlue,项目名称:Nocturne,代码行数:9,代码来源:EnigmaReaderTest.java


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