Java Code Examples for jdk.nashorn.internal.runtime.Source#readFully()

The following examples show how to use jdk.nashorn.internal.runtime.Source#readFully() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NashornScriptEngine.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("resource")
private static char[] loadEngineJSSource() {
    final String script = "resources/engine.js";
    try {
        final InputStream is = AccessController.doPrivileged(
                new PrivilegedExceptionAction<InputStream>() {
                    @Override
                    public InputStream run() throws Exception {
                        final URL url = NashornScriptEngine.class.getResource(script);
                        return url.openStream();
                    }
                });
        return Source.readFully(new InputStreamReader(is));
    } catch (final PrivilegedActionException | IOException e) {
        if (Context.DEBUG) {
            e.printStackTrace();
        }
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: NashornScriptEngine.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("resource")
private static char[] loadEngineJSSource() {
    final String script = "resources/engine.js";
    try {
        final InputStream is = AccessController.doPrivileged(
                new PrivilegedExceptionAction<InputStream>() {
                    @Override
                    public InputStream run() throws Exception {
                        final URL url = NashornScriptEngine.class.getResource(script);
                        return url.openStream();
                    }
                });
        return Source.readFully(new InputStreamReader(is));
    } catch (final PrivilegedActionException | IOException e) {
        if (Context.DEBUG) {
            e.printStackTrace();
        }
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: NashornScriptEngine.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Source makeSource(final Reader reader, final ScriptContext ctxt) throws ScriptException {
    try {
        if (reader instanceof URLReader) {
            final URL url = ((URLReader)reader).getURL();
            final Charset cs = ((URLReader)reader).getCharset();
            return new Source(url.toString(), url, cs);
        }
        return new Source(getScriptName(ctxt), Source.readFully(reader));
    } catch (final IOException e) {
        throw new ScriptException(e);
    }
}
 
Example 4
Source File: NashornScriptEngine.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Source makeSource(final Reader reader, final ScriptContext ctxt) throws ScriptException {
    try {
        if (reader instanceof URLReader) {
            final URL url = ((URLReader)reader).getURL();
            final Charset cs = ((URLReader)reader).getCharset();
            return new Source(url.toString(), url, cs);
        } else {
            return new Source(getScriptName(ctxt), Source.readFully(reader));
        }
    } catch (final IOException ioExp) {
        throw new ScriptException(ioExp);
    }
}
 
Example 5
Source File: NashornScriptEngine.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static Source makeSource(final Reader reader, final ScriptContext ctxt) throws ScriptException {
    try {
        if (reader instanceof URLReader) {
            final URL url = ((URLReader)reader).getURL();
            final Charset cs = ((URLReader)reader).getCharset();
            return new Source(url.toString(), url, cs);
        }
        return new Source(getScriptName(ctxt), Source.readFully(reader));
    } catch (final IOException e) {
        throw new ScriptException(e);
    }
}
 
Example 6
Source File: SourceHelper.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 7
Source File: SourceHelper.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final Reader reader) throws IOException {
    return new String(Source.readFully(reader));
}
 
Example 8
Source File: SourceHelper.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 9
Source File: SourceHelper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 10
Source File: CompilerTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void compileJSFile(final File file, final TestFilter filter) {
    if (VERBOSE) {
        log("Begin compiling " + file.getAbsolutePath());
    }

    final ScriptObject oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);

    try {
        final char[] buffer = Source.readFully(file);
        boolean excluded = false;

        if (filter != null) {
            final String content = new String(buffer);
            excluded = filter.exclude(file, content);
        }

        if (excluded) {
            if (VERBOSE) {
                log("Skipping " + file.getAbsolutePath());
            }
            skipped++;
            return;
        }

        if (globalChanged) {
            Context.setGlobal(global);
        }
        final Source source = new Source(file.getAbsolutePath(), buffer);
        final ScriptFunction script = context.compileScript(source, global);
        if (script == null || context.getErrorManager().getNumberOfErrors() > 0) {
            log("Compile failed: " + file.getAbsolutePath());
            failed++;
        } else {
            passed++;
        }
    } catch (final Throwable t) {
        log("Compile failed: " + file.getAbsolutePath() + " : " + t);
        if (VERBOSE) {
            t.printStackTrace(System.out);
        }
        failed++;
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    if (VERBOSE) {
        log("Done compiling " + file.getAbsolutePath());
    }
}
 
Example 11
Source File: ParserTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void parseJSFile(final File file, final TestFilter filter) {
    if (VERBOSE) {
        log("Begin parsing " + file.getAbsolutePath());
    }

    try {
        final char[] buffer = Source.readFully(file);
        boolean excluded = false;
        if (filter != null) {
            final String content = new String(buffer);
            excluded = filter.exclude(file, content);
        }

        if (excluded) {
            if (VERBOSE) {
                log("Skipping " + file.getAbsolutePath());
            }
            skipped++;
            return;
        }

        final ErrorManager errors = new ErrorManager() {
            @Override
            public void error(final String msg) {
                log(msg);
            }
        };
        errors.setLimit(0);
        final Source   source   = new Source(file.getAbsolutePath(), buffer);
        new Parser(context.getEnv(), source, errors).parse();
        if (errors.getNumberOfErrors() > 0) {
            log("Parse failed: " + file.getAbsolutePath());
            failed++;
        } else {
            passed++;
        }
    } catch (final Throwable exp) {
        log("Parse failed: " + file.getAbsolutePath() + " : " + exp);
        if (VERBOSE) {
            exp.printStackTrace(System.out);
        }
        failed++;
    }

    if (VERBOSE) {
        log("Done parsing " + file.getAbsolutePath());
    }
}
 
Example 12
Source File: SourceHelper.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final Reader reader) throws IOException {
    return new String(Source.readFully(reader));
}
 
Example 13
Source File: SourceHelper.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 14
Source File: SourceHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final Reader reader) throws IOException {
    return new String(Source.readFully(reader));
}
 
Example 15
Source File: SourceHelper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final Reader reader) throws IOException {
    return new String(Source.readFully(reader));
}
 
Example 16
Source File: SourceHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final Reader reader) throws IOException {
    return new String(Source.readFully(reader));
}
 
Example 17
Source File: SourceHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 18
Source File: SourceHelper.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 19
Source File: SourceHelper.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final File file) throws IOException {
    return new String(Source.readFully(file));
}
 
Example 20
Source File: SourceHelper.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static String readFully(final Reader reader) throws IOException {
    return new String(Source.readFully(reader));
}