Java Script Engine evaluateScriptResource(ScriptEngine engine, String resource)

Here you can find the source of evaluateScriptResource(ScriptEngine engine, String resource)

Description

evaluate Script Resource

License

Apache License

Declaration

public static synchronized Object evaluateScriptResource(ScriptEngine engine, String resource)
            throws IOException, ScriptException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.google.common.io.CharStreams;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static synchronized Object evaluateScriptResource(ScriptEngine engine, String resource)
            throws IOException, ScriptException {
        String script = getScriptResource(resource);
        return engine.eval(script);
    }//  w ww  .  jav a2s. com

    public static synchronized String getScriptResource(String resource) throws IOException {
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream is = classloader.getResourceAsStream(resource);
        InputStreamReader reader = new InputStreamReader(is);
        return CharStreams.toString(reader);
    }
}

Related

  1. compile(ScriptEngine engine, String script)
  2. createNashornEngine()
  3. getAppleScriptEngine()
  4. getAvailableEngineGroups()
  5. getDefaultScriptEngineManager()
  6. getEngine()