| @@ -17,7 +17,7 @@ | ||
| */ | ||
| package org.apidesign.bck2brwsr.launcher.fximpl; | ||
|
|
||
| import net.java.html.js.JavaScriptBody; | ||
|
|
||
| /** | ||
| * | ||
| @@ -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); | ||
| } | ||
| } | ||
| } | ||
| } |
| @@ -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>'\r'</code>), a newline character | ||
| * (<code>'\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 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>'\r'</code> and | ||
| * <code>'\n'</code>, which are converted to just | ||
| * <i>k</i>/2 <code>'\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; | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -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); | ||
| } | ||
| } |
| @@ -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™ 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> | ||
| * @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(); | ||
| } |