alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (urlreader.js)

This example Java source code file (urlreader.js) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

file, jstring, sourcehelper, url, urlreader

The urlreader.js Java example source code

/**
 * JDK-8008305: ScriptEngine.eval should offer the ability to provide a codebase
 *
 * @test
 * @run
 */

var URLReader = Java.type("jdk.nashorn.api.scripting.URLReader");
var URL = Java.type("java.net.URL");
var File = Java.type("java.io.File");
var JString = Java.type("java.lang.String");
var SourceHelper = Java.type("jdk.nashorn.test.models.SourceHelper");

var url = new File(__FILE__).toURI().toURL();
var reader = new URLReader(url);

// check URLReader.getURL() method
//Assert.assertEquals(url, reader.getURL());

// check URL read
// read URL content by directly reading from URL
var str = SourceHelper.readFully(url);
// read URL content via URLReader
var content = new JString(SourceHelper.readFully(reader));

// assert that the content is same
Assert.assertEquals(str, content);

Other Java examples (source code examples)

Here is a short list of links related to this Java urlreader.js source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.