@@ -34,6 +34,7 @@
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebEngine;
@@ -68,7 +69,9 @@ public void start(Stage primaryStage) throws Exception {
hbox.setStyle( "-fx-background-color: #808080;");
hbox.setAlignment(Pos.CENTER);
hbox.getChildren().add(vbox);
HBox.setHgrow(vbox, Priority.ALWAYS);
vbox.getChildren().add(view);
VBox.setVgrow(view, Priority.ALWAYS);

BorderPane root = new BorderPane();
final boolean showToolbar = "true".equals(this.getParameters().getNamed().get("toolbar")); // NOI18N
@@ -19,24 +19,30 @@

import java.io.BufferedReader;
import java.io.Reader;
import org.apidesign.html.boot.spi.Fn;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.TooManyListenersException;
import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
import org.apidesign.html.boot.impl.FindResources;
import org.apidesign.html.boot.impl.FnUtils;
import org.apidesign.html.boot.spi.Fn;
import org.netbeans.html.boot.impl.FindResources;
import org.netbeans.html.boot.impl.FnUtils;

/**
*
* @author Jaroslav Tulach <jtulach@netbeans.org>
*/
public final class JVMBridge {
static final Logger LOG = Logger.getLogger(JVMBridge.class.getName());

private final WebEngine engine;
private final ClassLoader cl;
private final WebPresenter presenter;
@@ -70,11 +76,12 @@ public static void onBck2BrwsrLoad() {
}

public Class<?> loadClass(String name) throws ClassNotFoundException {
FnUtils.currentPresenter(presenter);
Fn.activate(presenter);
return Class.forName(name, true, cl);
}

private final class WebPresenter implements FindResources, Fn.Presenter {
private final class WebPresenter
implements FindResources, Fn.Presenter, Fn.ToJavaScript, Fn.FromJavaScript, Executor {
@Override
public void findResources(String name, Collection<? super URL> results, boolean oneIsEnough) {
if (ldrs != null) for (ClassLoader l : ldrs) {
@@ -87,6 +94,9 @@ public void findResources(String name, Collection<? super URL> results, boolean

@Override
public Fn defineFn(String code, String... names) {
return defineJSFn(code, names);
}
private JSFn defineJSFn(String code, String... names) {
StringBuilder sb = new StringBuilder();
sb.append("(function() {");
sb.append(" return function(");
@@ -122,6 +132,91 @@ public void loadScript(Reader code) throws Exception {
}
engine.executeScript(sb.toString());
}

@Override
public Object toJava(Object js) {
return checkArray(js);
}

@Override
public Object toJavaScript(Object toReturn) {
if (toReturn instanceof Object[]) {
return convertArrays((Object[]) toReturn);
}
return toReturn;
}

@Override
public void execute(Runnable command) {
if (Platform.isFxApplicationThread()) {
command.run();
} else {
Platform.runLater(command);
}
}

final JSObject convertArrays(Object[] arr) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] instanceof Object[]) {
arr[i] = convertArrays((Object[]) arr[i]);
}
}
final JSObject wrapArr = (JSObject) wrapArrFn().call("array", arr); // NOI18N
return wrapArr;
}

private JSObject wrapArrImpl;

private final JSObject wrapArrFn() {
if (wrapArrImpl == null) {
try {
wrapArrImpl = (JSObject) defineJSFn(" var k = {};"
+ " k.array= function() {"
+ " return Array.prototype.slice.call(arguments);"
+ " };"
+ " return k;"
).invokeImpl(null, false);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
return wrapArrImpl;
}

final Object checkArray(Object val) {
int length = ((Number) arraySizeFn().call("array", val, null)).intValue();
if (length == -1) {
return val;
}
Object[] arr = new Object[length];
arraySizeFn().call("array", val, arr);
return arr;
}
private JSObject arraySize;

private final JSObject arraySizeFn() {
if (arraySize == null) {
try {
arraySize = (JSObject) defineJSFn(" var k = {};"
+ " k.array = function(arr, to) {"
+ " if (to === null) {"
+ " if (Object.prototype.toString.call(arr) === '[object Array]') return arr.length;"
+ " else return -1;"
+ " } else {"
+ " var l = arr.length;"
+ " for (var i = 0; i < l; i++) to[i] = arr[i];"
+ " return l;"
+ " }"
+ " };"
+ " return k;"
).invokeImpl(null, false);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
return arraySize;
}

}

private static final class JSFn extends Fn {
@@ -134,12 +229,29 @@ private JSFn(WebPresenter cl, JSObject fn) {

@Override
public Object invoke(Object thiz, Object... args) throws Exception {
return invokeImpl(thiz, true, args);
}

final Object invokeImpl(Object thiz, boolean arrayChecks, Object... args) throws Exception {
try {
List<Object> all = new ArrayList<Object>(args.length + 1);
all.add(thiz == null ? fn : thiz);
all.addAll(Arrays.asList(args));
for (int i = 0; i < args.length; i++) {
if (arrayChecks && args[i] instanceof Object[]) {
Object[] arr = (Object[]) args[i];
Object conv = ((WebPresenter) presenter()).convertArrays(arr);
args[i] = conv;
}
all.add(args[i]);
}
Object ret = fn.call("call", all.toArray()); // NOI18N
return ret == fn ? null : ret;
if (ret == fn) {
return null;
}
if (!arrayChecks) {
return ret;
}
return ((WebPresenter) presenter()).checkArray(ret);
} catch (Error t) {
t.printStackTrace();
throw t;
@@ -15,21 +15,12 @@
* along with this program. Look for COPYING file in the top folder.
* If not, see http://opensource.org/licenses/GPL-2.0.
*/

package org.apidesign.bck2brwsr.launcher.fximpl;

/**
*
* @author Jaroslav Tulach <jtulach@netbeans.org>
*/
public final class Run implements Runnable {
private final Runnable r;
Run(Runnable r) {
this.r = r;
}

@Override
public void run() {
r.run();
}
interface OnMessage {
public void onMessage(String msg);
}
@@ -31,8 +31,8 @@
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.apidesign.html.boot.spi.Fn;
import org.apidesign.html.boot.impl.FindResources;
import org.apidesign.html.boot.impl.FnUtils;
import org.netbeans.html.boot.impl.FindResources;
import org.netbeans.html.boot.impl.FnUtils;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@@ -92,7 +92,7 @@ public Object invoke(Object thiz, Object... args) throws Exception {
all.addAll(Arrays.asList(args));
Invocable inv = (Invocable)eng;
Object ret = inv.invokeMethod(val, "call", all.toArray());
return ret == val ? null : ret;
return val.equals(ret) ? null : ret;
}
};
} catch (ScriptException ex) {
@@ -118,7 +118,7 @@ public void loadScript(Reader code) throws Exception {
}

@BeforeMethod public void registerPresenter() {
FnUtils.currentPresenter(presenter);
Fn.activate(presenter);
}

@Test public void noParamMethod() throws Throwable {
@@ -17,7 +17,7 @@
*/
package org.apidesign.bck2brwsr.launcher.fximpl;

import org.apidesign.bck2brwsr.core.JavaScriptBody;
import net.java.html.js.JavaScriptBody;

/**
*
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>launcher-pom</artifactId>
<version>0.8</version>
<version>0.8.1</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>launcher.http</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<name>Bck2Brwsr Launcher</name>
<url>http://maven.apache.org</url>
<build>
@@ -17,8 +17,15 @@
*/
package org.apidesign.bck2brwsr.launcher;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import org.apidesign.vm4brwsr.Bck2Brwsr;

/**
@@ -42,19 +49,57 @@ void generateBck2BrwsrJS(StringBuilder sb, final Res loader) throws IOException
class R implements Bck2Brwsr.Resources {
@Override
public InputStream get(String resource) throws IOException {
return loader.get(resource);
return loader.get(resource, 0);
}
}

Bck2Brwsr.generate(sb, new R());
String b2b = System.getProperty("bck2brwsr.js");
if (b2b != null) {
LOG.log(Level.INFO, "Serving bck2brwsr.js from {0}", b2b);
URL bu;
try {
bu = new URL(b2b);
} catch (MalformedURLException ex) {
File f = new File(b2b);
if (f.exists()) {
bu = f.toURI().toURL();
} else {
throw ex;
}
}
try (Reader r = new InputStreamReader(bu.openStream())) {
char[] arr = new char[4096];
for (;;) {
int len = r.read(arr);
if (len == -1) {
break;
}
sb.append(arr, 0, len);
}
}
} else {
LOG.log(Level.INFO, "Generating bck2brwsr.js from scratch", b2b);
Bck2Brwsr.generate(sb, new R());
}
sb.append(
"(function WrapperVM(global) {"
+ " function ldCls(res) {\n"
"(function WrapperVM(global) {\n"
+ " var cache = {};\n"
+ " function ldCls(res, skip) {\n"
+ " var c = cache[res];\n"
+ " if (c) {\n"
+ " if (c[skip]) return c[skip];\n"
+ " if (c[skip] === null) return null;\n"
+ " } else {\n"
+ " cache[res] = c = new Array();\n"
+ " }\n"
+ " var request = new XMLHttpRequest();\n"
+ " request.open('GET', '/classes/' + res, false);\n"
+ " request.open('GET', '/classes/' + res + '?skip=' + skip, false);\n"
+ " request.send();\n"
+ " if (request.status !== 200) return null;\n"
+ " if (request.status !== 200) {\n"
+ " c[skip] = null;\n"
+ " return null;\n"
+ " }\n"
+ " var arr = eval('(' + request.responseText + ')');\n"
+ " c[skip] = arr;\n"
+ " return arr;\n"
+ " }\n"
+ " var prevvm = global.bck2brwsr;\n"
@@ -65,6 +110,7 @@ public InputStream get(String resource) throws IOException {
+ " };\n"
+ "})(this);\n"
);
LOG.log(Level.INFO, "Serving bck2brwsr.js", b2b);
}

}
@@ -126,6 +126,10 @@ public InputStream get(String resource) throws IOException {
u = en.nextElement();
}
if (u != null) {
if (u.toExternalForm().contains("rt.jar")) {
LOG.log(Level.WARNING, "No fallback to bootclasspath for {0}", u);
return null;
}
return u.openStream();
}
}
@@ -220,14 +220,22 @@ static String invoke(String clazz, String method) throws
* @return the array of bytes in the given resource
* @throws IOException I/O in case something goes wrong
*/
public static byte[] read(String name) throws IOException {
public static byte[] read(String name, int skip) throws IOException {
URL u = null;
Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
while (en.hasMoreElements()) {
u = en.nextElement();
if (!name.endsWith(".class")) {
u = getResource(name, skip);
} else {
Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
while (en.hasMoreElements()) {
u = en.nextElement();
}
}
if (u == null) {
throw new IOException("Can't find " + name);
if (name.endsWith(".class")) {
throw new IOException("Can't find " + name);
} else {
return null;
}
}
try (InputStream is = u.openStream()) {
byte[] arr;
@@ -244,6 +252,19 @@ public static byte[] read(String name) throws IOException {
}
}

private static URL getResource(String resource, int skip) throws IOException {
URL u = null;
Enumeration<URL> en = Console.class.getClassLoader().getResources(resource);
while (en.hasMoreElements()) {
final URL now = en.nextElement();
if (--skip < 0) {
u = now;
break;
}
}
return u;
}

@JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
private static void turnAssetionStatusOn() {
}
@@ -4,11 +4,11 @@
<parent>
<artifactId>bck2brwsr</artifactId>
<groupId>org.apidesign</groupId>
<version>0.8</version>
<version>0.8.1</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>launcher-pom</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<packaging>pom</packaging>
<name>Launchers</name>
<properties>
13 pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apidesign</groupId>
<artifactId>bck2brwsr</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<packaging>pom</packaging>
<name>Back 2 Browser</name>
<parent>
@@ -13,15 +13,14 @@
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.version>RELEASE73</netbeans.version>
<netbeans.version>RELEASE74</netbeans.version>
<license>COPYING</license>
<net.java.html.version>0.6</net.java.html.version>
<net.java.html.version>0.7.5</net.java.html.version>
<netbeans.compile.on.save>none</netbeans.compile.on.save>
</properties>
<modules>
<module>dew</module>
<module>javaquery</module>
<module>benchmarks</module>
<module>ide</module>
<module>ko</module>
<module>launcher</module>
<module>rt</module>
@@ -41,7 +40,7 @@
<connection>scm:hg:http://source.apidesign.org/hg/bck2brwsr</connection>
<developerConnection>scm:hg:https://source.apidesign.org/hg/bck2brwsr</developerConnection>
<url>http://source.apidesign.org/hg/bck2brwsr</url>
<tag>release-0.8</tag>
<tag>release-0.8.1</tag>
</scm>
<repositories>
<repository>
@@ -90,10 +89,8 @@
<exclude>rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java</exclude>
<exclude>rt/archetype/src/main/resources/archetype-resources/**</exclude>
<exclude>rt/emul/compact/src/test/resources/**</exclude>
<exclude>dew/src/main/resources/org/apidesign/bck2brwsr/dew/**</exclude>
<exclude>javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout*.js</exclude>
<exclude>ko/archetype/src/main/resources/archetype-resources/**</exclude>
<exclude>ko/*/src/main/resources/org/apidesign/*/*/knockout-2.2.1.js</exclude>
</excludes>
</configuration>
</plugin>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>rt</artifactId>
<version>0.8</version>
<version>0.8.1</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>core</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<name>Bck2Brwsr Native Annotations</name>
<url>http://maven.apache.org</url>
<build>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.8</version>
<version>0.8.1</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>brwsrtest</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<name>Tests Inside Real Browser</name>
<url>http://maven.apache.org</url>
<properties>
@@ -4,11 +4,11 @@
<parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul.pom</artifactId>
<version>0.8</version>
<version>0.8.1</version>
</parent>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<name>Bck2Brwsr API Profile</name>
<url>http://maven.apache.org</url>
<properties>

Large diffs are not rendered by default.

@@ -0,0 +1,146 @@
/*
* Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/

package java.io;

import java.util.concurrent.atomic.AtomicInteger;

/**
* Instances of the file descriptor class serve as an opaque handle
* to the underlying machine-specific structure representing an open
* file, an open socket, or another source or sink of bytes. The
* main practical use for a file descriptor is to create a
* <code>FileInputStream</code> or <code>FileOutputStream</code> to
* contain it.
* <p>
* Applications should not create their own file descriptors.
*
* @author Pavani Diwanji
* @see java.io.FileInputStream
* @see java.io.FileOutputStream
* @since JDK1.0
*/
public final class FileDescriptor {

private int fd;

/**
* A counter for tracking the FIS/FOS/RAF instances that
* use this FileDescriptor. The FIS/FOS.finalize() will not release
* the FileDescriptor if it is still under user by a stream.
*/
private AtomicInteger useCount;

/**
* Constructs an (invalid) FileDescriptor
* object.
*/
public /**/ FileDescriptor() {
fd = -1;
useCount = new AtomicInteger();
}

private /* */ FileDescriptor(int fd) {
this.fd = fd;
useCount = new AtomicInteger();
}

/**
* A handle to the standard input stream. Usually, this file
* descriptor is not used directly, but rather via the input stream
* known as <code>System.in</code>.
*
* @see java.lang.System#in
*/
public static final FileDescriptor in = new FileDescriptor(0);

/**
* A handle to the standard output stream. Usually, this file
* descriptor is not used directly, but rather via the output stream
* known as <code>System.out</code>.
* @see java.lang.System#out
*/
public static final FileDescriptor out = new FileDescriptor(1);

/**
* A handle to the standard error stream. Usually, this file
* descriptor is not used directly, but rather via the output stream
* known as <code>System.err</code>.
*
* @see java.lang.System#err
*/
public static final FileDescriptor err = new FileDescriptor(2);

/**
* Tests if this file descriptor object is valid.
*
* @return <code>true</code> if the file descriptor object represents a
* valid, open file, socket, or other active I/O connection;
* <code>false</code> otherwise.
*/
public boolean valid() {
return fd != -1;
}

/**
* Force all system buffers to synchronize with the underlying
* device. This method returns after all modified data and
* attributes of this FileDescriptor have been written to the
* relevant device(s). In particular, if this FileDescriptor
* refers to a physical storage medium, such as a file in a file
* system, sync will not return until all in-memory modified copies
* of buffers associated with this FileDescriptor have been
* written to the physical medium.
*
* sync is meant to be used by code that requires physical
* storage (such as a file) to be in a known state For
* example, a class that provided a simple transaction facility
* might use sync to ensure that all changes to a file caused
* by a given transaction were recorded on a storage medium.
*
* sync only affects buffers downstream of this FileDescriptor. If
* any in-memory buffering is being done by the application (for
* example, by a BufferedOutputStream object), those buffers must
* be flushed into the FileDescriptor (for example, by invoking
* OutputStream.flush) before that data will be affected by sync.
*
* @exception SyncFailedException
* Thrown when the buffers cannot be flushed,
* or because the system cannot guarantee that all the
* buffers have been synchronized with physical media.
* @since JDK1.1
*/
public native void sync() throws SyncFailedException;

// package private methods used by FIS, FOS and RAF

int incrementAndGetUseCount() {
return useCount.incrementAndGet();
}

int decrementAndGetUseCount() {
return useCount.decrementAndGet();
}
}
@@ -0,0 +1,382 @@
/*
* Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;



/**
* A <code>FileInputStream</code> obtains input bytes
* from a file in a file system. What files
* are available depends on the host environment.
*
* <p><code>FileInputStream</code> is meant for reading streams of raw bytes
* such as image data. For reading streams of characters, consider using
* <code>FileReader</code>.
*
* @author Arthur van Hoff
* @see java.io.File
* @see java.io.FileDescriptor
* @see java.io.FileOutputStream
* @see java.nio.file.Files#newInputStream
* @since JDK1.0
*/
public
class FileInputStream extends InputStream
{
/* File Descriptor - handle to the open file */
private final FileDescriptor fd;

// private FileChannel channel = null;

private final Object closeLock = new Object();
private volatile boolean closed = false;

private static final ThreadLocal<Boolean> runningFinalize =
new ThreadLocal<>();

private static boolean isRunningFinalize() {
Boolean val;
if ((val = runningFinalize.get()) != null)
return val.booleanValue();
return false;
}

/**
* Creates a <code>FileInputStream</code> by
* opening a connection to an actual file,
* the file named by the path name <code>name</code>
* in the file system. A new <code>FileDescriptor</code>
* object is created to represent this file
* connection.
* <p>
* First, if there is a security
* manager, its <code>checkRead</code> method
* is called with the <code>name</code> argument
* as its argument.
* <p>
* If the named file does not exist, is a directory rather than a regular
* file, or for some other reason cannot be opened for reading then a
* <code>FileNotFoundException</code> is thrown.
*
* @param name the system-dependent file name.
* @exception FileNotFoundException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
* @exception SecurityException if a security manager exists and its
* <code>checkRead</code> method denies read access
* to the file.
* @see java.lang.SecurityManager#checkRead(java.lang.String)
*/
public FileInputStream(String name) throws FileNotFoundException {
this(name != null ? new File(name) : null);
}

/**
* Creates a <code>FileInputStream</code> by
* opening a connection to an actual file,
* the file named by the <code>File</code>
* object <code>file</code> in the file system.
* A new <code>FileDescriptor</code> object
* is created to represent this file connection.
* <p>
* First, if there is a security manager,
* its <code>checkRead</code> method is called
* with the path represented by the <code>file</code>
* argument as its argument.
* <p>
* If the named file does not exist, is a directory rather than a regular
* file, or for some other reason cannot be opened for reading then a
* <code>FileNotFoundException</code> is thrown.
*
* @param file the file to be opened for reading.
* @exception FileNotFoundException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
* @exception SecurityException if a security manager exists and its
* <code>checkRead</code> method denies read access to the file.
* @see java.io.File#getPath()
* @see java.lang.SecurityManager#checkRead(java.lang.String)
*/
public FileInputStream(File file) throws FileNotFoundException {
throw new SecurityException();
}

/**
* Creates a <code>FileInputStream</code> by using the file descriptor
* <code>fdObj</code>, which represents an existing connection to an
* actual file in the file system.
* <p>
* If there is a security manager, its <code>checkRead</code> method is
* called with the file descriptor <code>fdObj</code> as its argument to
* see if it's ok to read the file descriptor. If read access is denied
* to the file descriptor a <code>SecurityException</code> is thrown.
* <p>
* If <code>fdObj</code> is null then a <code>NullPointerException</code>
* is thrown.
* <p>
* This constructor does not throw an exception if <code>fdObj</code>
* is {@link java.io.FileDescriptor#valid() invalid}.
* However, if the methods are invoked on the resulting stream to attempt
* I/O on the stream, an <code>IOException</code> is thrown.
*
* @param fdObj the file descriptor to be opened for reading.
* @throws SecurityException if a security manager exists and its
* <code>checkRead</code> method denies read access to the
* file descriptor.
* @see SecurityManager#checkRead(java.io.FileDescriptor)
*/
public FileInputStream(FileDescriptor fdObj) {
throw new SecurityException();
}

/**
* Opens the specified file for reading.
* @param name the name of the file
*/
private native void open(String name) throws FileNotFoundException;

/**
* Reads a byte of data from this input stream. This method blocks
* if no input is yet available.
*
* @return the next byte of data, or <code>-1</code> if the end of the
* file is reached.
* @exception IOException if an I/O error occurs.
*/
public native int read() throws IOException;

/**
* Reads a subarray as a sequence of bytes.
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
private native int readBytes(byte b[], int off, int len) throws IOException;

/**
* Reads up to <code>b.length</code> bytes of data from this input
* stream into an array of bytes. This method blocks until some input
* is available.
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the file has been reached.
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[]) throws IOException {
return readBytes(b, 0, b.length);
}

/**
* Reads up to <code>len</code> bytes of data from this input stream
* into an array of bytes. If <code>len</code> is not zero, the method
* blocks until some input is available; otherwise, no
* bytes are read and <code>0</code> is returned.
*
* @param b the buffer into which the data is read.
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the file has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[], int off, int len) throws IOException {
return readBytes(b, off, len);
}

/**
* Skips over and discards <code>n</code> bytes of data from the
* input stream.
*
* <p>The <code>skip</code> method may, for a variety of
* reasons, end up skipping over some smaller number of bytes,
* possibly <code>0</code>. If <code>n</code> is negative, an
* <code>IOException</code> is thrown, even though the <code>skip</code>
* method of the {@link InputStream} superclass does nothing in this case.
* The actual number of bytes skipped is returned.
*
* <p>This method may skip more bytes than are remaining in the backing
* file. This produces no exception and the number of bytes skipped
* may include some number of bytes that were beyond the EOF of the
* backing file. Attempting to read from the stream after skipping past
* the end will result in -1 indicating the end of the file.
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException if n is negative, if the stream does not
* support seek, or if an I/O error occurs.
*/
public native long skip(long n) throws IOException;

/**
* Returns an estimate of the number of remaining bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* invocation of a method for this input stream. The next invocation might be
* the same thread or another thread. A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
*
* <p> In some cases, a non-blocking read (or skip) may appear to be
* blocked when it is merely slow, for example when reading large
* files over slow networks.
*
* @return an estimate of the number of remaining bytes that can be read
* (or skipped over) from this input stream without blocking.
* @exception IOException if this file input stream has been closed by calling
* {@code close} or an I/O error occurs.
*/
public native int available() throws IOException;

/**
* Closes this file input stream and releases any system resources
* associated with the stream.
*
* <p> If this stream has an associated channel then the channel is closed
* as well.
*
* @exception IOException if an I/O error occurs.
*
* @revised 1.4
* @spec JSR-51
*/
public void close() throws IOException {
synchronized (closeLock) {
if (closed) {
return;
}
closed = true;
}
// if (channel != null) {
// /*
// * Decrement the FD use count associated with the channel
// * The use count is incremented whenever a new channel
// * is obtained from this stream.
// */
// fd.decrementAndGetUseCount();
// channel.close();
// }

/*
* Decrement the FD use count associated with this stream
*/
int useCount = fd.decrementAndGetUseCount();

/*
* If FileDescriptor is still in use by another stream, the finalizer
* will not close it.
*/
if ((useCount <= 0) || !isRunningFinalize()) {
close0();
}
}

/**
* Returns the <code>FileDescriptor</code>
* object that represents the connection to
* the actual file in the file system being
* used by this <code>FileInputStream</code>.
*
* @return the file descriptor object associated with this stream.
* @exception IOException if an I/O error occurs.
* @see java.io.FileDescriptor
*/
public final FileDescriptor getFD() throws IOException {
if (fd != null) return fd;
throw new IOException();
}

/**
* Returns the unique {@link java.nio.channels.FileChannel FileChannel}
* object associated with this file input stream.
*
* <p> The initial {@link java.nio.channels.FileChannel#position()
* </code>position<code>} of the returned channel will be equal to the
* number of bytes read from the file so far. Reading bytes from this
* stream will increment the channel's position. Changing the channel's
* position, either explicitly or by reading, will change this stream's
* file position.
*
* @return the file channel associated with this file input stream
*
* @since 1.4
* @spec JSR-51
*/
// public FileChannel getChannel() {
// synchronized (this) {
// if (channel == null) {
// channel = FileChannelImpl.open(fd, true, false, this);
//
// /*
// * Increment fd's use count. Invoking the channel's close()
// * method will result in decrementing the use count set for
// * the channel.
// */
// fd.incrementAndGetUseCount();
// }
// return channel;
// }
// }

private static native void initIDs();

private native void close0() throws IOException;

static {
initIDs();
}

/**
* Ensures that the <code>close</code> method of this file input stream is
* called when there are no more references to it.
*
* @exception IOException if an I/O error occurs.
* @see java.io.FileInputStream#close()
*/
protected void finalize() throws IOException {
if ((fd != null) && (fd != FileDescriptor.in)) {

/*
* Finalizer should not release the FileDescriptor if another
* stream is still using it. If the user directly invokes
* close() then the FileDescriptor is also released.
*/
runningFinalize.set(Boolean.TRUE);
try {
close();
} finally {
runningFinalize.set(Boolean.FALSE);
}
}
}
}

Large diffs are not rendered by default.

@@ -0,0 +1,85 @@
/*
* Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* Convenience class for reading character files. The constructors of this
* class assume that the default character encoding and the default byte-buffer
* size are appropriate. To specify these values yourself, construct an
* InputStreamReader on a FileInputStream.
*
* <p><code>FileReader</code> is meant for reading streams of characters.
* For reading streams of raw bytes, consider using a
* <code>FileInputStream</code>.
*
* @see InputStreamReader
* @see FileInputStream
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class FileReader extends InputStreamReader {

/**
* Creates a new <tt>FileReader</tt>, given the name of the
* file to read from.
*
* @param fileName the name of the file to read from
* @exception FileNotFoundException if the named file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
*/
public FileReader(String fileName) throws FileNotFoundException {
super(new FileInputStream(fileName));
}

/**
* Creates a new <tt>FileReader</tt>, given the <tt>File</tt>
* to read from.
*
* @param file the <tt>File</tt> to read from
* @exception FileNotFoundException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
*/
public FileReader(File file) throws FileNotFoundException {
super(new FileInputStream(file));
}

/**
* Creates a new <tt>FileReader</tt>, given the
* <tt>FileDescriptor</tt> to read from.
*
* @param fd the FileDescriptor to read from
*/
public FileReader(FileDescriptor fd) {
super(new FileInputStream(fd));
}

}
@@ -0,0 +1,119 @@
/*
* Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* Convenience class for writing character files. The constructors of this
* class assume that the default character encoding and the default byte-buffer
* size are acceptable. To specify these values yourself, construct an
* OutputStreamWriter on a FileOutputStream.
*
* <p>Whether or not a file is available or may be created depends upon the
* underlying platform. Some platforms, in particular, allow a file to be
* opened for writing by only one <tt>FileWriter</tt> (or other file-writing
* object) at a time. In such situations the constructors in this class
* will fail if the file involved is already open.
*
* <p><code>FileWriter</code> is meant for writing streams of characters.
* For writing streams of raw bytes, consider using a
* <code>FileOutputStream</code>.
*
* @see OutputStreamWriter
* @see FileOutputStream
*
* @author Mark Reinhold
* @since JDK1.1
*/

public class FileWriter extends OutputStreamWriter {

/**
* Constructs a FileWriter object given a file name.
*
* @param fileName String The system-dependent filename.
* @throws IOException if the named file exists but is a directory rather
* than a regular file, does not exist but cannot be
* created, or cannot be opened for any other reason
*/
public FileWriter(String fileName) throws IOException {
super(new FileOutputStream(fileName));
}

/**
* Constructs a FileWriter object given a file name with a boolean
* indicating whether or not to append the data written.
*
* @param fileName String The system-dependent filename.
* @param append boolean if <code>true</code>, then data will be written
* to the end of the file rather than the beginning.
* @throws IOException if the named file exists but is a directory rather
* than a regular file, does not exist but cannot be
* created, or cannot be opened for any other reason
*/
public FileWriter(String fileName, boolean append) throws IOException {
super(new FileOutputStream(fileName, append));
}

/**
* Constructs a FileWriter object given a File object.
*
* @param file a File object to write to.
* @throws IOException if the file exists but is a directory rather than
* a regular file, does not exist but cannot be created,
* or cannot be opened for any other reason
*/
public FileWriter(File file) throws IOException {
super(new FileOutputStream(file));
}

/**
* Constructs a FileWriter object given a File object. If the second
* argument is <code>true</code>, then bytes will be written to the end
* of the file rather than the beginning.
*
* @param file a File object to write to
* @param append if <code>true</code>, then bytes will be written
* to the end of the file rather than the beginning
* @throws IOException if the file exists but is a directory rather than
* a regular file, does not exist but cannot be created,
* or cannot be opened for any other reason
* @since 1.4
*/
public FileWriter(File file, boolean append) throws IOException {
super(new FileOutputStream(file, append));
}

/**
* Constructs a FileWriter object associated with a file descriptor.
*
* @param fd FileDescriptor object to write to.
*/
public FileWriter(FileDescriptor fd) {
super(new FileOutputStream(fd));
}

}
@@ -0,0 +1,124 @@
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* Abstract class for reading filtered character streams.
* The abstract class <code>FilterReader</code> itself
* provides default methods that pass all requests to
* the contained stream. Subclasses of <code>FilterReader</code>
* should override some of these methods and may also provide
* additional methods and fields.
*
* @author Mark Reinhold
* @since JDK1.1
*/

public abstract class FilterReader extends Reader {

/**
* The underlying character-input stream.
*/
protected Reader in;

/**
* Creates a new filtered reader.
*
* @param in a Reader object providing the underlying stream.
* @throws NullPointerException if <code>in</code> is <code>null</code>
*/
protected FilterReader(Reader in) {
super(in);
this.in = in;
}

/**
* Reads a single character.
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
return in.read();
}

/**
* Reads characters into a portion of an array.
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
return in.read(cbuf, off, len);
}

/**
* Skips characters.
*
* @exception IOException If an I/O error occurs
*/
public long skip(long n) throws IOException {
return in.skip(n);
}

/**
* Tells whether this stream is ready to be read.
*
* @exception IOException If an I/O error occurs
*/
public boolean ready() throws IOException {
return in.ready();
}

/**
* Tells whether this stream supports the mark() operation.
*/
public boolean markSupported() {
return in.markSupported();
}

/**
* Marks the present position in the stream.
*
* @exception IOException If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
in.mark(readAheadLimit);
}

/**
* Resets the stream.
*
* @exception IOException If an I/O error occurs
*/
public void reset() throws IOException {
in.reset();
}

public void close() throws IOException {
in.close();
}

}
@@ -0,0 +1,107 @@
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* Abstract class for writing filtered character streams.
* The abstract class <code>FilterWriter</code> itself
* provides default methods that pass all requests to the
* contained stream. Subclasses of <code>FilterWriter</code>
* should override some of these methods and may also
* provide additional methods and fields.
*
* @author Mark Reinhold
* @since JDK1.1
*/

public abstract class FilterWriter extends Writer {

/**
* The underlying character-output stream.
*/
protected Writer out;

/**
* Create a new filtered writer.
*
* @param out a Writer object to provide the underlying stream.
* @throws NullPointerException if <code>out</code> is <code>null</code>
*/
protected FilterWriter(Writer out) {
super(out);
this.out = out;
}

/**
* Writes a single character.
*
* @exception IOException If an I/O error occurs
*/
public void write(int c) throws IOException {
out.write(c);
}

/**
* Writes a portion of an array of characters.
*
* @param cbuf Buffer of characters to be written
* @param off Offset from which to start reading characters
* @param len Number of characters to be written
*
* @exception IOException If an I/O error occurs
*/
public void write(char cbuf[], int off, int len) throws IOException {
out.write(cbuf, off, len);
}

/**
* Writes a portion of a string.
*
* @param str String to be written
* @param off Offset from which to start reading characters
* @param len Number of characters to be written
*
* @exception IOException If an I/O error occurs
*/
public void write(String str, int off, int len) throws IOException {
out.write(str, off, len);
}

/**
* Flushes the stream.
*
* @exception IOException If an I/O error occurs
*/
public void flush() throws IOException {
out.flush();
}

public void close() throws IOException {
out.close();
}

}
@@ -0,0 +1,292 @@
/*
* Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;

/**
* This class is an input stream filter that provides the added
* functionality of keeping track of the current line number.
* <p>
* A line is a sequence of bytes ending with a carriage return
* character (<code>'&#92;r'</code>), a newline character
* (<code>'&#92;n'</code>), or a carriage return character followed
* immediately by a linefeed character. In all three cases, the line
* terminating character(s) are returned as a single newline character.
* <p>
* The line number begins at <code>0</code>, and is incremented by
* <code>1</code> when a <code>read</code> returns a newline character.
*
* @author Arthur van Hoff
* @see java.io.LineNumberReader
* @since JDK1.0
* @deprecated This class incorrectly assumes that bytes adequately represent
* characters. As of JDK&nbsp;1.1, the preferred way to operate on
* character streams is via the new character-stream classes, which
* include a class for counting line numbers.
*/
@Deprecated
public
class LineNumberInputStream extends FilterInputStream {
int pushBack = -1;
int lineNumber;
int markLineNumber;
int markPushBack = -1;

/**
* Constructs a newline number input stream that reads its input
* from the specified input stream.
*
* @param in the underlying input stream.
*/
public LineNumberInputStream(InputStream in) {
super(in);
}

/**
* Reads the next byte of data from this input stream. The value
* byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned. This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* <p>
* The <code>read</code> method of
* <code>LineNumberInputStream</code> calls the <code>read</code>
* method of the underlying input stream. It checks for carriage
* returns and newline characters in the input, and modifies the
* current line number as appropriate. A carriage-return character or
* a carriage return followed by a newline character are both
* converted into a single newline character.
*
* @return the next byte of data, or <code>-1</code> if the end of this
* stream is reached.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#getLineNumber()
*/
public int read() throws IOException {
int c = pushBack;

if (c != -1) {
pushBack = -1;
} else {
c = in.read();
}

switch (c) {
case '\r':
pushBack = in.read();
if (pushBack == '\n') {
pushBack = -1;
}
case '\n':
lineNumber++;
return '\n';
}
return c;
}

/**
* Reads up to <code>len</code> bytes of data from this input stream
* into an array of bytes. This method blocks until some input is available.
* <p>
* The <code>read</code> method of
* <code>LineNumberInputStream</code> repeatedly calls the
* <code>read</code> method of zero arguments to fill in the byte array.
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* this stream has been reached.
* @exception IOException if an I/O error occurs.
* @see java.io.LineNumberInputStream#read()
*/
public int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}

int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c;

int i = 1;
try {
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
if (b != null) {
b[off + i] = (byte)c;
}
}
} catch (IOException ee) {
}
return i;
}

/**
* Skips over and discards <code>n</code> bytes of data from this
* input stream. The <code>skip</code> method may, for a variety of
* reasons, end up skipping over some smaller number of bytes,
* possibly <code>0</code>. The actual number of bytes skipped is
* returned. If <code>n</code> is negative, no bytes are skipped.
* <p>
* The <code>skip</code> method of <code>LineNumberInputStream</code> creates
* a byte array and then repeatedly reads into it until
* <code>n</code> bytes have been read or the end of the stream has
* been reached.
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public long skip(long n) throws IOException {
int chunk = 2048;
long remaining = n;
byte data[];
int nr;

if (n <= 0) {
return 0;
}

data = new byte[chunk];
while (remaining > 0) {
nr = read(data, 0, (int) Math.min(chunk, remaining));
if (nr < 0) {
break;
}
remaining -= nr;
}

return n - remaining;
}

/**
* Sets the line number to the specified argument.
*
* @param lineNumber the new line number.
* @see #getLineNumber
*/
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}

/**
* Returns the current line number.
*
* @return the current line number.
* @see #setLineNumber
*/
public int getLineNumber() {
return lineNumber;
}


/**
* Returns the number of bytes that can be read from this input
* stream without blocking.
* <p>
* Note that if the underlying input stream is able to supply
* <i>k</i> input characters without blocking, the
* <code>LineNumberInputStream</code> can guarantee only to provide
* <i>k</i>/2 characters without blocking, because the
* <i>k</i> characters from the underlying input stream might
* consist of <i>k</i>/2 pairs of <code>'&#92;r'</code> and
* <code>'&#92;n'</code>, which are converted to just
* <i>k</i>/2 <code>'&#92;n'</code> characters.
*
* @return the number of bytes that can be read from this input stream
* without blocking.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public int available() throws IOException {
return (pushBack == -1) ? super.available()/2 : super.available()/2 + 1;
}

/**
* Marks the current position in this input stream. A subsequent
* call to the <code>reset</code> method repositions this stream at
* the last marked position so that subsequent reads re-read the same bytes.
* <p>
* The <code>mark</code> method of
* <code>LineNumberInputStream</code> remembers the current line
* number in a private variable, and then calls the <code>mark</code>
* method of the underlying input stream.
*
* @param readlimit the maximum limit of bytes that can be read before
* the mark position becomes invalid.
* @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#reset()
*/
public void mark(int readlimit) {
markLineNumber = lineNumber;
markPushBack = pushBack;
in.mark(readlimit);
}

/**
* Repositions this stream to the position at the time the
* <code>mark</code> method was last called on this input stream.
* <p>
* The <code>reset</code> method of
* <code>LineNumberInputStream</code> resets the line number to be
* the line number at the time the <code>mark</code> method was
* called, and then calls the <code>reset</code> method of the
* underlying input stream.
* <p>
* Stream marks are intended to be used in
* situations where you need to read ahead a little to see what's in
* the stream. Often this is most easily done by invoking some
* general parser. If the stream is of the type handled by the
* parser, it just chugs along happily. If the stream is not of
* that type, the parser should toss an exception when it fails,
* which, if it happens within readlimit bytes, allows the outer
* code to reset the stream and try another parser.
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#mark(int)
*/
public void reset() throws IOException {
lineNumber = markLineNumber;
pushBack = markPushBack;
in.reset();
}
}
@@ -0,0 +1,281 @@
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* A buffered character-input stream that keeps track of line numbers. This
* class defines methods {@link #setLineNumber(int)} and {@link
* #getLineNumber()} for setting and getting the current line number
* respectively.
*
* <p> By default, line numbering begins at 0. This number increments at every
* <a href="#lt">line terminator</a> as the data is read, and can be changed
* with a call to <tt>setLineNumber(int)</tt>. Note however, that
* <tt>setLineNumber(int)</tt> does not actually change the current position in
* the stream; it only changes the value that will be returned by
* <tt>getLineNumber()</tt>.
*
* <p> A line is considered to be <a name="lt">terminated</a> by any one of a
* line feed ('\n'), a carriage return ('\r'), or a carriage return followed
* immediately by a linefeed.
*
* @author Mark Reinhold
* @since JDK1.1
*/

public class LineNumberReader extends BufferedReader {

/** The current line number */
private int lineNumber = 0;

/** The line number of the mark, if any */
private int markedLineNumber; // Defaults to 0

/** If the next character is a line feed, skip it */
private boolean skipLF;

/** The skipLF flag when the mark was set */
private boolean markedSkipLF;

/**
* Create a new line-numbering reader, using the default input-buffer
* size.
*
* @param in
* A Reader object to provide the underlying stream
*/
public LineNumberReader(Reader in) {
super(in);
}

/**
* Create a new line-numbering reader, reading characters into a buffer of
* the given size.
*
* @param in
* A Reader object to provide the underlying stream
*
* @param sz
* An int specifying the size of the buffer
*/
public LineNumberReader(Reader in, int sz) {
super(in, sz);
}

/**
* Set the current line number.
*
* @param lineNumber
* An int specifying the line number
*
* @see #getLineNumber
*/
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}

/**
* Get the current line number.
*
* @return The current line number
*
* @see #setLineNumber
*/
public int getLineNumber() {
return lineNumber;
}

/**
* Read a single character. <a href="#lt">Line terminators</a> are
* compressed into single newline ('\n') characters. Whenever a line
* terminator is read the current line number is incremented.
*
* @return The character read, or -1 if the end of the stream has been
* reached
*
* @throws IOException
* If an I/O error occurs
*/
public int read() throws IOException {
synchronized (lock) {
int c = super.read();
if (skipLF) {
if (c == '\n')
c = super.read();
skipLF = false;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
lineNumber++;
return '\n';
}
return c;
}
}

/**
* Read characters into a portion of an array. Whenever a <a
* href="#lt">line terminator</a> is read the current line number is
* incremented.
*
* @param cbuf
* Destination buffer
*
* @param off
* Offset at which to start storing characters
*
* @param len
* Maximum number of characters to read
*
* @return The number of bytes read, or -1 if the end of the stream has
* already been reached
*
* @throws IOException
* If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
int n = super.read(cbuf, off, len);

for (int i = off; i < off + n; i++) {
int c = cbuf[i];
if (skipLF) {
skipLF = false;
if (c == '\n')
continue;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
lineNumber++;
break;
}
}

return n;
}
}

/**
* Read a line of text. Whenever a <a href="#lt">line terminator</a> is
* read the current line number is incremented.
*
* @return A String containing the contents of the line, not including
* any <a href="#lt">line termination characters</a>, or
* <tt>null</tt> if the end of the stream has been reached
*
* @throws IOException
* If an I/O error occurs
*/
public String readLine() throws IOException {
synchronized (lock) {
String l = super.readLine(skipLF);
skipLF = false;
if (l != null)
lineNumber++;
return l;
}
}

/** Maximum skip-buffer size */
private static final int maxSkipBufferSize = 8192;

/** Skip buffer, null until allocated */
private char skipBuffer[] = null;

/**
* Skip characters.
*
* @param n
* The number of characters to skip
*
* @return The number of characters actually skipped
*
* @throws IOException
* If an I/O error occurs
*
* @throws IllegalArgumentException
* If <tt>n</tt> is negative
*/
public long skip(long n) throws IOException {
if (n < 0)
throw new IllegalArgumentException("skip() value is negative");
int nn = (int) Math.min(n, maxSkipBufferSize);
synchronized (lock) {
if ((skipBuffer == null) || (skipBuffer.length < nn))
skipBuffer = new char[nn];
long r = n;
while (r > 0) {
int nc = read(skipBuffer, 0, (int) Math.min(r, nn));
if (nc == -1)
break;
r -= nc;
}
return n - r;
}
}

/**
* Mark the present position in the stream. Subsequent calls to reset()
* will attempt to reposition the stream to this point, and will also reset
* the line number appropriately.
*
* @param readAheadLimit
* Limit on the number of characters that may be read while still
* preserving the mark. After reading this many characters,
* attempting to reset the stream may fail.
*
* @throws IOException
* If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
synchronized (lock) {
super.mark(readAheadLimit);
markedLineNumber = lineNumber;
markedSkipLF = skipLF;
}
}

/**
* Reset the stream to the most recent mark.
*
* @throws IOException
* If the stream has not been marked, or if the mark has been
* invalidated
*/
public void reset() throws IOException {
synchronized (lock) {
super.reset();
lineNumber = markedLineNumber;
skipLF = markedSkipLF;
}
}

}
@@ -25,6 +25,8 @@

package java.io;

import java.nio.charset.Charset;

/**
* An OutputStreamWriter is a bridge from character streams to byte streams:
* Characters written to it are encoded into bytes using a specified {@link
@@ -116,12 +118,9 @@ public OutputStreamWriter(OutputStream out) {
* @since 1.4
* @spec JSR-51
*/
// public OutputStreamWriter(OutputStream out, Charset cs) {
// super(out);
// if (cs == null)
// throw new NullPointerException("charset");
// se = StreamEncoder.forOutputStreamWriter(out, this, cs);
// }
public OutputStreamWriter(OutputStream out, Charset cs) {
this(out);
}

/**
* Creates an OutputStreamWriter that uses the given charset encoder. </p>
@@ -25,6 +25,7 @@

package java.io;

import java.nio.charset.Charset;
import java.util.Arrays;


@@ -88,9 +89,6 @@ private PrintStream(boolean autoFlush, OutputStream out) {
static final class Formatter {
}

static final class Charset {
}

static Charset toCharset(String ch) throws UnsupportedEncodingException {
if (!"UTF-8".equals(ch)) {
throw new UnsupportedEncodingException();
@@ -25,10 +25,9 @@

package java.io;

import java.io.PrintStream.Charset;
import java.io.PrintStream.Formatter;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Objects;

/**
* Prints formatted representations of objects to a text-output stream. This
@@ -0,0 +1,201 @@
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* A character stream whose source is a string.
*
* @author Mark Reinhold
* @since JDK1.1
*/

public class StringReader extends Reader {

private String str;
private int length;
private int next = 0;
private int mark = 0;

/**
* Creates a new string reader.
*
* @param s String providing the character stream.
*/
public StringReader(String s) {
this.str = s;
this.length = s.length();
}

/** Check to make sure that the stream has not been closed */
private void ensureOpen() throws IOException {
if (str == null)
throw new IOException("Stream closed");
}

/**
* Reads a single character.
*
* @return The character read, or -1 if the end of the stream has been
* reached
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
synchronized (lock) {
ensureOpen();
if (next >= length)
return -1;
return str.charAt(next++);
}
}

/**
* Reads characters into a portion of an array.
*
* @param cbuf Destination buffer
* @param off Offset at which to start writing characters
* @param len Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
if (next >= length)
return -1;
int n = Math.min(length - next, len);
str.getChars(next, next + n, cbuf, off);
next += n;
return n;
}
}

/**
* Skips the specified number of characters in the stream. Returns
* the number of characters that were skipped.
*
* <p>The <code>ns</code> parameter may be negative, even though the
* <code>skip</code> method of the {@link Reader} superclass throws
* an exception in this case. Negative values of <code>ns</code> cause the
* stream to skip backwards. Negative return values indicate a skip
* backwards. It is not possible to skip backwards past the beginning of
* the string.
*
* <p>If the entire string has been read or skipped, then this method has
* no effect and always returns 0.
*
* @exception IOException If an I/O error occurs
*/
public long skip(long ns) throws IOException {
synchronized (lock) {
ensureOpen();
if (next >= length)
return 0;
// Bound skip by beginning and end of the source
long n = Math.min(length - next, ns);
n = Math.max(-next, n);
next += n;
return n;
}
}

/**
* Tells whether this stream is ready to be read.
*
* @return True if the next read() is guaranteed not to block for input
*
* @exception IOException If the stream is closed
*/
public boolean ready() throws IOException {
synchronized (lock) {
ensureOpen();
return true;
}
}

/**
* Tells whether this stream supports the mark() operation, which it does.
*/
public boolean markSupported() {
return true;
}

/**
* Marks the present position in the stream. Subsequent calls to reset()
* will reposition the stream to this point.
*
* @param readAheadLimit Limit on the number of characters that may be
* read while still preserving the mark. Because
* the stream's input comes from a string, there
* is no actual limit, so this argument must not
* be negative, but is otherwise ignored.
*
* @exception IllegalArgumentException If readAheadLimit is < 0
* @exception IOException If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
if (readAheadLimit < 0){
throw new IllegalArgumentException("Read-ahead limit < 0");
}
synchronized (lock) {
ensureOpen();
mark = next;
}
}

/**
* Resets the stream to the most recent mark, or to the beginning of the
* string if it has never been marked.
*
* @exception IOException If an I/O error occurs
*/
public void reset() throws IOException {
synchronized (lock) {
ensureOpen();
next = mark;
}
}

/**
* Closes the stream and releases any system resources associated with
* it. Once the stream has been closed, further read(),
* ready(), mark(), or reset() invocations will throw an IOException.
* Closing a previously closed stream has no effect.
*/
public void close() {
str = null;
}
}
@@ -0,0 +1,236 @@
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;


/**
* A character stream that collects its output in a string buffer, which can
* then be used to construct a string.
* <p>
* Closing a <tt>StringWriter</tt> has no effect. The methods in this class
* can be called after the stream has been closed without generating an
* <tt>IOException</tt>.
*
* @author Mark Reinhold
* @since JDK1.1
*/

public class StringWriter extends Writer {

private StringBuffer buf;

/**
* Create a new string writer using the default initial string-buffer
* size.
*/
public StringWriter() {
buf = new StringBuffer();
lock = buf;
}

/**
* Create a new string writer using the specified initial string-buffer
* size.
*
* @param initialSize
* The number of <tt>char</tt> values that will fit into this buffer
* before it is automatically expanded
*
* @throws IllegalArgumentException
* If <tt>initialSize</tt> is negative
*/
public StringWriter(int initialSize) {
if (initialSize < 0) {
throw new IllegalArgumentException("Negative buffer size");
}
buf = new StringBuffer(initialSize);
lock = buf;
}

/**
* Write a single character.
*/
public void write(int c) {
buf.append((char) c);
}

/**
* Write a portion of an array of characters.
*
* @param cbuf Array of characters
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(char cbuf[], int off, int len) {
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
buf.append(cbuf, off, len);
}

/**
* Write a string.
*/
public void write(String str) {
buf.append(str);
}

/**
* Write a portion of a string.
*
* @param str String to be written
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(String str, int off, int len) {
buf.append(str.substring(off, off + len));
}

/**
* Appends the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(csq.toString()) </pre>
*
* <p> Depending on the specification of <tt>toString</tt> for the
* character sequence <tt>csq</tt>, the entire sequence may not be
* appended. For instance, invoking the <tt>toString</tt> method of a
* character buffer will return a subsequence whose content depends upon
* the buffer's position and limit.
*
* @param csq
* The character sequence to append. If <tt>csq</tt> is
* <tt>null</tt>, then the four characters <tt>"null"</tt> are
* appended to this writer.
*
* @return This writer
*
* @since 1.5
*/
public StringWriter append(CharSequence csq) {
if (csq == null)
write("null");
else
write(csq.toString());
return this;
}

/**
* Appends a subsequence of the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq, start,
* end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
* exactly the same way as the invocation
*
* <pre>
* out.write(csq.subSequence(start, end).toString()) </pre>
*
* @param csq
* The character sequence from which a subsequence will be
* appended. If <tt>csq</tt> is <tt>null</tt>, then characters
* will be appended as if <tt>csq</tt> contained the four
* characters <tt>"null"</tt>.
*
* @param start
* The index of the first character in the subsequence
*
* @param end
* The index of the character following the last character in the
* subsequence
*
* @return This writer
*
* @throws IndexOutOfBoundsException
* If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
* is greater than <tt>end</tt>, or <tt>end</tt> is greater than
* <tt>csq.length()</tt>
*
* @since 1.5
*/
public StringWriter append(CharSequence csq, int start, int end) {
CharSequence cs = (csq == null ? "null" : csq);
write(cs.subSequence(start, end).toString());
return this;
}

/**
* Appends the specified character to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(c)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(c) </pre>
*
* @param c
* The 16-bit character to append
*
* @return This writer
*
* @since 1.5
*/
public StringWriter append(char c) {
write(c);
return this;
}

/**
* Return the buffer's current value as a string.
*/
public String toString() {
return buf.toString();
}

/**
* Return the string buffer itself.
*
* @return StringBuffer holding the current buffer value.
*/
public StringBuffer getBuffer() {
return buf;
}

/**
* Flush the stream.
*/
public void flush() {
}

/**
* Closing a <tt>StringWriter</tt> has no effect. The methods in this
* class can be called after the stream has been closed without generating
* an <tt>IOException</tt>.
*/
public void close() throws IOException {
}

}
@@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;

/**
* Signals that a sync operation has failed.
*
* @author Ken Arnold
* @see java.io.FileDescriptor#sync
* @see java.io.IOException
* @since JDK1.1
*/
public class SyncFailedException extends IOException {
private static final long serialVersionUID = -2353342684412443330L;

/**
* Constructs an SyncFailedException with a detail message.
* A detail message is a String that describes this particular exception.
*
* @param desc a String describing the exception.
*/
public SyncFailedException(String desc) {
super(desc);
}
}
@@ -17,6 +17,13 @@
*/
package java.lang;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Properties;
import org.apidesign.bck2brwsr.core.JavaScriptBody;

/** Poor man's re-implementation of most important System methods.
@@ -40,13 +47,27 @@ public static int identityHashCode(Object obj) {
}

public static String getProperty(String name) {
if ("os.name".equals(name)) {
return userAgent();
}
return null;
}

@JavaScriptBody(args = {}, body = "return (typeof navigator !== 'undefined') ? navigator.userAgent : 'unknown';")
private static native String userAgent();

public static String getProperty(String key, String def) {
return def;
}

public static Properties getProperties() {
throw new SecurityException();
}

public static void setProperties(Properties p) {
throw new SecurityException();
}

/**
* Returns the system-dependent line separator string. It always
* returns the same value - the initial value of the {@linkplain
@@ -62,4 +83,49 @@ public static String lineSeparator() {
@JavaScriptBody(args = { "exitCode" }, body = "window.close();")
public static void exit(int exitCode) {
}

public final static InputStream in;

public final static PrintStream out;

public final static PrintStream err;

public static void setOut(PrintStream out) {
throw new SecurityException();
}

public static void setIn(InputStream in) {
throw new SecurityException();
}

public static void setErr(PrintStream err) {
throw new SecurityException();
}

static {
in = new ByteArrayInputStream(new byte[0]);
out = new PrintStream(new BufferedOutputStream(new SystemStream("log")));
err = new PrintStream(new BufferedOutputStream(new SystemStream("warn")));
}

private static final class SystemStream extends OutputStream {
private final String method;

public SystemStream(String method) {
this.method = method;
}

@Override
public void write(byte b[], int off, int len) throws IOException {
write(method, new String(b, off, len, "UTF-8"));
}

@JavaScriptBody(args = { "method", "b" }, body = "if (typeof console !== 'undefined') console[method](b.toString());")
private static native void write(String method, String b);

@Override
public void write(int b) throws IOException {
write(new byte[] { (byte)b });
}
} // end of SystemStream
}
@@ -1165,7 +1165,7 @@ public String toString() {
* @since 1.2
*/
public ClassLoader getContextClassLoader() {
return null;
return ClassLoader.getSystemClassLoader();
}

/**
@@ -1191,6 +1191,9 @@ public ClassLoader getContextClassLoader() {
* @since 1.2
*/
public void setContextClassLoader(ClassLoader cl) {
if (cl == ClassLoader.getSystemClassLoader()) {
return;
}
throw new SecurityException();
}

@@ -0,0 +1,131 @@
/*
* Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.lang.annotation;

/**
* The common interface extended by all annotation types. Note that an
* interface that manually extends this one does <i>not</i> define
* an annotation type. Also note that this interface does not itself
* define an annotation type.
*
* More information about annotation types can be found in section 9.6 of
* <cite>The Java&trade; Language Specification</cite>.
*
* @author Josh Bloch
* @since 1.5
*/
public interface Annotation {
/**
* Returns true if the specified object represents an annotation
* that is logically equivalent to this one. In other words,
* returns true if the specified object is an instance of the same
* annotation type as this instance, all of whose members are equal
* to the corresponding member of this annotation, as defined below:
* <ul>
* <li>Two corresponding primitive typed members whose values are
* <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
* unless their type is <tt>float</tt> or <tt>double</tt>.
*
* <li>Two corresponding <tt>float</tt> members whose values
* are <tt>x</tt> and <tt>y</tt> are considered equal if
* <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
* (Unlike the <tt>==</tt> operator, NaN is considered equal
* to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
*
* <li>Two corresponding <tt>double</tt> members whose values
* are <tt>x</tt> and <tt>y</tt> are considered equal if
* <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
* (Unlike the <tt>==</tt> operator, NaN is considered equal
* to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
*
* <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
* annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
* are considered equal if <tt>x.equals(y)</tt>. (Note that this
* definition is recursive for annotation typed members.)
*
* <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
* are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
* appropriate overloading of {@link java.util.Arrays#equals}.
* </ul>
*
* @return true if the specified object represents an annotation
* that is logically equivalent to this one, otherwise false
*/
boolean equals(Object obj);

/**
* Returns the hash code of this annotation, as defined below:
*
* <p>The hash code of an annotation is the sum of the hash codes
* of its members (including those with default values), as defined
* below:
*
* The hash code of an annotation member is (127 times the hash code
* of the member-name as computed by {@link String#hashCode()}) XOR
* the hash code of the member-value, as defined below:
*
* <p>The hash code of a member-value depends on its type:
* <ul>
* <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
* <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
* <tt><i>WrapperType</i></tt> is the wrapper type corresponding
* to the primitive type of <tt><i>v</i></tt> ({@link Byte},
* {@link Character}, {@link Double}, {@link Float}, {@link Integer},
* {@link Long}, {@link Short}, or {@link Boolean}).
*
* <li>The hash code of a string, enum, class, or annotation member-value
I <tt><i>v</i></tt> is computed as by calling
* <tt><i>v</i>.hashCode()</tt>. (In the case of annotation
* member values, this is a recursive definition.)
*
* <li>The hash code of an array member-value is computed by calling
* the appropriate overloading of
* {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
* on the value. (There is one overloading for each primitive
* type, and one for object reference types.)
* </ul>
*
* @return the hash code of this annotation
*/
int hashCode();

/**
* Returns a string representation of this annotation. The details
* of the representation are implementation-dependent, but the following
* may be regarded as typical:
* <pre>
* &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
* </pre>
*
* @return a string representation of this annotation
*/
String toString();

/**
* Returns the annotation type of this annotation.
*/
Class<? extends Annotation> annotationType();
}