Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Rhino JavaScript Java Library Source Code
Rhino JavaScript Java Library is an open-source implementation of JavaScript
written entirely in Java.
Rhino JavaScript Java Library Source Code files are provided in binary package (rhino-1.7.14.zip).
You can also browse the source code below:
✍: FYIcenter.com
⏎ org/mozilla/javascript/tools/SourceReader.java
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.javascript.tools;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.mozilla.javascript.Kit;
import org.mozilla.javascript.commonjs.module.provider.ParsedContentType;
/**
* @author Attila Szegedi
* @version $Id: SourceReader.java,v 1.2 2010/02/15 19:31:17 szegedia%freemail.hu Exp $
*/
public class SourceReader
{
public static URL toUrl(String path) {
// Assume path is URL if it contains a colon and there are at least
// 2 characters in the protocol part. The later allows under Windows
// to interpret paths with driver letter as file, not URL.
if (path.indexOf(':') >= 2) {
try {
return new URL(path);
} catch (MalformedURLException ex) {
// not a URL
}
}
return null;
}
public static Object readFileOrUrl(String path, boolean convertToString,
String defaultEncoding) throws IOException
{
URL url = toUrl(path);
InputStream is = null;
int capacityHint = 0;
String encoding;
final String contentType;
byte[] data;
try {
if (url == null) {
File file = new File(path);
contentType = encoding = null;
capacityHint = (int)file.length();
is = new FileInputStream(file);
} else {
URLConnection uc = url.openConnection();
is = uc.getInputStream();
if(convertToString) {
ParsedContentType pct = new ParsedContentType(uc.getContentType());
contentType = pct.getContentType();
encoding = pct.getEncoding();
}
else {
contentType = encoding = null;
}
capacityHint = uc.getContentLength();
// Ignore insane values for Content-Length
if (capacityHint > (1 << 20)) {
capacityHint = -1;
}
}
if (capacityHint <= 0) {
capacityHint = 4096;
}
data = Kit.readStream(is, capacityHint);
} finally {
if(is != null) {
is.close();
}
}
Object result;
if (!convertToString) {
result = data;
} else {
if(encoding == null) {
// None explicitly specified in Content-type header. Use RFC-4329
// 4.2.2 section to autodetect
if(data.length > 3 && data[0] == -1 && data[1] == -2 && data[2] == 0 && data[3] == 0) {
encoding = "UTF-32LE";
}
else if(data.length > 3 && data[0] == 0 && data[1] == 0 && data[2] == -2 && data[3] == -1) {
encoding = "UTF-32BE";
}
else if(data.length > 2 && data[0] == -17 && data[1] == -69 && data[2] == -65) {
encoding = "UTF-8";
}
else if(data.length > 1 && data[0] == -1 && data[1] == -2) {
encoding = "UTF-16LE";
}
else if(data.length > 1 && data[0] == -2 && data[1] == -1) {
encoding = "UTF-16BE";
}
else {
// No autodetect. See if we have explicit value on command line
encoding = defaultEncoding;
if(encoding == null) {
// No explicit encoding specification
if(url == null) {
// Local files default to system encoding
encoding = System.getProperty("file.encoding");
}
else if(contentType != null && contentType.startsWith("application/")) {
// application/* types default to UTF-8
encoding = "UTF-8";
}
else {
// text/* MIME types default to US-ASCII
encoding = "US-ASCII";
}
}
}
}
String strResult = new String(data, encoding);
// Skip BOM
if(strResult.length() > 0 && strResult.charAt(0) == '\uFEFF')
{
strResult = strResult.substring(1);
}
result = strResult;
}
return result;
}
}
⏎ org/mozilla/javascript/tools/SourceReader.java
Or download all of them as a single archive file:
File name: rhino-1.7.14-sources.jar File size: 1029165 bytes Release date: 2022-01-06 Download
⇒ Example code to Test rhino-runtime-1.7.14.jar
⇐ Download Rhino JavaScript Binary Package
2022-05-03, ≈207🔥, 1💬
Popular Posts:
JDK 11 jdk.jartool.jmod is the JMOD file for JDK 11 JAR tool, which can be invoked by the "jar" comm...
iText is an ideal library for developers looking to enhance web- and other applications with dynamic...
Apache Log4j 1.2 Bridge allows applications coded to use Log4j 1.2 API to use Log4j 2 instead. Bytec...
Where to find answers to frequently asked questions on Downloading and Installing ojdbc.jar - JDBC D...
What Is junit-3.8.1.jar? junit-3.8.1.jar is the version 3.8.1 of JUnit JAR library file. JUnit is a ...