You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/01/04 18:47:05 UTC
svn commit: r492652 [5/13] -
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileOutputStream.java Thu Jan 4 09:47:01 2007
@@ -17,11 +17,11 @@
package java.io;
-
import java.nio.channels.FileChannel;
import org.apache.harmony.luni.platform.IFileSystem;
import org.apache.harmony.luni.platform.Platform;
+import org.apache.harmony.luni.util.Msg;
import org.apache.harmony.nio.FileChannelFactory;
/**
@@ -36,85 +36,85 @@
*
* @see FileInputStream
*/
-public class FileOutputStream extends OutputStream implements Closeable{
+public class FileOutputStream extends OutputStream implements Closeable {
- /**
- * The FileDescriptor representing this FileOutputStream.
- */
- FileDescriptor fd;
+ /**
+ * The FileDescriptor representing this FileOutputStream.
+ */
+ FileDescriptor fd;
boolean innerFD;
// The unique file channel associated with this FileInputStream (lazily
- // initialized).
- private FileChannel channel;
+ // initialized).
+ private FileChannel channel;
private IFileSystem fileSystem = Platform.getFileSystem();
- /**
- * Constructs a new FileOutputStream on the File <code>file</code>. If
- * the file exists, it is written over. See the constructor which can append
- * to the file if so desired.
- *
- * @param file
- * the File on which to stream reads.
- *
- * @throws FileNotFoundException
- * If the <code>file</code> cannot be opened for writing.
- *
- * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
- */
- public FileOutputStream(File file) throws FileNotFoundException {
- this(file, false);
- }
-
- /**
- * Constructs a new FileOutputStream on the File <code>file</code>. If
- * the file exists, it is written over. The parameter <code>append</code>
- * determines whether or not the file is opened and appended to or just
- * opened empty.
- *
- * @param file
- * the File on which to stream reads.
- * @param append
- * a boolean indicating whether or not to append to an existing
- * file.
- *
- * @throws FileNotFoundException
- * If the <code>file</code> cannot be opened for writing.
- *
- * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
- * @see java.lang.SecurityManager#checkWrite(String)
- */
- public FileOutputStream(File file, boolean append)
- throws FileNotFoundException {
- super();
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
+ /**
+ * Constructs a new FileOutputStream on the File <code>file</code>. If
+ * the file exists, it is written over. See the constructor which can append
+ * to the file if so desired.
+ *
+ * @param file
+ * the File on which to stream reads.
+ *
+ * @throws FileNotFoundException
+ * If the <code>file</code> cannot be opened for writing.
+ *
+ * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
+ */
+ public FileOutputStream(File file) throws FileNotFoundException {
+ this(file, false);
+ }
+
+ /**
+ * Constructs a new FileOutputStream on the File <code>file</code>. If
+ * the file exists, it is written over. The parameter <code>append</code>
+ * determines whether or not the file is opened and appended to or just
+ * opened empty.
+ *
+ * @param file
+ * the File on which to stream reads.
+ * @param append
+ * a boolean indicating whether or not to append to an existing
+ * file.
+ *
+ * @throws FileNotFoundException
+ * If the <code>file</code> cannot be opened for writing.
+ *
+ * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
+ * @see java.lang.SecurityManager#checkWrite(String)
+ */
+ public FileOutputStream(File file, boolean append)
+ throws FileNotFoundException {
+ super();
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
security.checkWrite(file.getPath());
}
- fd = new FileDescriptor();
- fd.descriptor = fileSystem.open(file.properPath(true), append?IFileSystem.O_APPEND:IFileSystem.O_WRONLY);
+ fd = new FileDescriptor();
+ fd.descriptor = fileSystem.open(file.properPath(true),
+ append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY);
innerFD = true;
channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- append? IFileSystem.O_APPEND:IFileSystem.O_WRONLY);
- }
+ append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY);
+ }
- /**
- * Constructs a new FileOutputStream on the FileDescriptor <code>fd</code>.
- * The file must already be open, therefore no <code>FileIOException</code>
- * will be thrown.
- *
- * @param fd
- * the FileDescriptor on which to stream writes.
- *
- * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
- */
- public FileOutputStream(FileDescriptor fd) {
- super();
+ /**
+ * Constructs a new FileOutputStream on the FileDescriptor <code>fd</code>.
+ * The file must already be open, therefore no <code>FileIOException</code>
+ * will be thrown.
+ *
+ * @param fd
+ * the FileDescriptor on which to stream writes.
+ *
+ * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
+ */
+ public FileOutputStream(FileDescriptor fd) {
+ super();
if (fd == null) {
- throw new NullPointerException(org.apache.harmony.luni.util.Msg
- .getString("K006c")); //$NON-NLS-1$
+ throw new NullPointerException(Msg.getString("K006c")); //$NON-NLS-1$
}
SecurityManager security = System.getSecurityManager();
if (security != null) {
@@ -124,52 +124,52 @@
innerFD = false;
channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
IFileSystem.O_WRONLY);
- }
+ }
+
+ /**
+ * Constructs a new FileOutputStream on the file named <code>fileName</code>.
+ * If the file exists, it is written over. See the constructor which can
+ * append to the file if so desired. The <code>fileName</code> may be
+ * absolute or relative to the System property <code>"user.dir"</code>.
+ *
+ * @param filename
+ * the file on which to stream writes.
+ *
+ * @throws FileNotFoundException
+ * If the <code>filename</code> cannot be opened for writing.
+ */
+ public FileOutputStream(String filename) throws FileNotFoundException {
+ this(filename, false);
+ }
+
+ /**
+ * Constructs a new FileOutputStream on the file named <code>filename</code>.
+ * If the file exists, it is written over. The parameter <code>append</code>
+ * determines whether or not the file is opened and appended to or just
+ * opened empty. The <code>filename</code> may be absolute or relative to
+ * the System property <code>"user.dir"</code>.
+ *
+ * @param filename
+ * the file on which to stream writes.
+ * @param append
+ * a boolean indicating whether or not to append to an existing
+ * file.
+ *
+ * @throws FileNotFoundException
+ * If the <code>filename</code> cannot be opened for writing.
+ */
+ public FileOutputStream(String filename, boolean append)
+ throws FileNotFoundException {
+ this(new File(filename), append);
+ }
- /**
- * Constructs a new FileOutputStream on the file named <code>fileName</code>.
- * If the file exists, it is written over. See the constructor which can
- * append to the file if so desired. The <code>fileName</code> may be
- * absolute or relative to the System property <code>"user.dir"</code>.
- *
- * @param filename
- * the file on which to stream writes.
- *
- * @throws FileNotFoundException
- * If the <code>filename</code> cannot be opened for writing.
- */
- public FileOutputStream(String filename) throws FileNotFoundException {
- this(filename, false);
- }
-
- /**
- * Constructs a new FileOutputStream on the file named <code>filename</code>.
- * If the file exists, it is written over. The parameter <code>append</code>
- * determines whether or not the file is opened and appended to or just
- * opened empty. The <code>filename</code> may be absolute or relative to
- * the System property <code>"user.dir"</code>.
- *
- * @param filename
- * the file on which to stream writes.
- * @param append
- * a boolean indicating whether or not to append to an existing
- * file.
- *
- * @throws FileNotFoundException
- * If the <code>filename</code> cannot be opened for writing.
- */
- public FileOutputStream(String filename, boolean append)
- throws FileNotFoundException {
- this(new File(filename), append);
- }
-
- /**
- * Close the FileOutputStream. This implementation closes the underlying OS
- * resources allocated to represent this stream.
- *
- * @throws IOException
- * If an error occurs attempting to close this FileOutputStream.
- */
+ /**
+ * Close the FileOutputStream. This implementation closes the underlying OS
+ * resources allocated to represent this stream.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this FileOutputStream.
+ */
@Override
public void close() throws IOException {
if (fd == null) {
@@ -194,85 +194,86 @@
}
}
- /**
+ /**
* Frees any resources allocated to represent this FileOutputStream before
* it is garbage collected. This method is called from the Java Virtual
* Machine.
*
- * @throws IOException If an error occurs attempting to finalize this
- * FileOutputStream.
+ * @throws IOException
+ * If an error occurs attempting to finalize this
+ * FileOutputStream.
*/
- @Override
+ @Override
protected void finalize() throws IOException {
- close();
- }
+ close();
+ }
- /**
- * Answers the FileChannel equivalent to this output stream.
- * <p>
- * The file channel is write-only and has an initial position within the
- * file that is the same as the current position of this FileOutputStream
- * within the file. All changes made to the underlying file descriptor state
- * via the channel are visible by the output stream and vice versa.
- * </p>
- *
- * @return the file channel representation for this FileOutputStream.
- */
- public FileChannel getChannel() {
+ /**
+ * Answers the FileChannel equivalent to this output stream.
+ * <p>
+ * The file channel is write-only and has an initial position within the
+ * file that is the same as the current position of this FileOutputStream
+ * within the file. All changes made to the underlying file descriptor state
+ * via the channel are visible by the output stream and vice versa.
+ * </p>
+ *
+ * @return the file channel representation for this FileOutputStream.
+ */
+ public FileChannel getChannel() {
return channel;
- }
+ }
+
+ /**
+ * Answers a FileDescriptor which represents the lowest level representation
+ * of a OS stream resource.
+ *
+ * @return a FileDescriptor representing this FileOutputStream.
+ *
+ * @throws IOException
+ * If the Stream is already closed and there is no
+ * FileDescriptor.
+ */
+ public final FileDescriptor getFD() throws IOException {
+ return fd;
+ }
- /**
- * Answers a FileDescriptor which represents the lowest level representation
- * of a OS stream resource.
- *
- * @return a FileDescriptor representing this FileOutputStream.
- *
- * @throws IOException
- * If the Stream is already closed and there is no
- * FileDescriptor.
- */
- public final FileDescriptor getFD() throws IOException {
- return fd;
- }
-
- /**
- * Writes the entire contents of the byte array <code>buffer</code> to
- * this FileOutputStream.
- *
- * @param buffer
- * the buffer to be written
- *
- * @throws IOException
- * If an error occurs attempting to write to this
- * FileOutputStream.
- */
- @Override
+ /**
+ * Writes the entire contents of the byte array <code>buffer</code> to
+ * this FileOutputStream.
+ *
+ * @param buffer
+ * the buffer to be written
+ *
+ * @throws IOException
+ * If an error occurs attempting to write to this
+ * FileOutputStream.
+ */
+ @Override
public void write(byte[] buffer) throws IOException {
- write(buffer, 0, buffer.length);
- }
+ write(buffer, 0, buffer.length);
+ }
- /**
- * Writes <code>count</code> <code>bytes</code> from the byte array
- * <code>buffer</code> starting at <code>offset</code> to this
- * FileOutputStream.
- *
- * @param buffer
- * the buffer to be written
- * @param offset
- * offset in buffer to get bytes
- * @param count
- * number of bytes in buffer to write
- *
- * @throws IOException
- * If an error occurs attempting to write to this
- * FileOutputStream.
- * @throws IndexOutOfBoundsException
- * If offset or count are outside of bounds.
- * @throws NullPointerException
- * If buffer is <code>null</code>.
- */
- @Override
+ /**
+ * Writes <code>count</code> <code>bytes</code> from the byte array
+ * <code>buffer</code> starting at <code>offset</code> to this
+ * FileOutputStream.
+ *
+ * @param buffer
+ * the buffer to be written
+ * @param offset
+ * offset in buffer to get bytes
+ * @param count
+ * number of bytes in buffer to write
+ *
+ * @throws IOException
+ * If an error occurs attempting to write to this
+ * FileOutputStream.
+ * @throws IndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ * @throws NullPointerException
+ * If buffer is <code>null</code>.
+ */
+ @Override
public void write(byte[] buffer, int offset, int count) throws IOException {
if (buffer == null) {
throw new NullPointerException();
@@ -282,7 +283,7 @@
throw new IndexOutOfBoundsException();
}
- if( count == 0 ) {
+ if (count == 0) {
return;
}
@@ -290,28 +291,29 @@
fileSystem.write(fd.descriptor, buffer, offset, count);
}
- /**
+ /**
* Writes the specified byte <code>oneByte</code> to this
* FileOutputStream. Only the low order byte of <code>oneByte</code> is
* written.
*
- * @param oneByte the byte to be written
+ * @param oneByte
+ * the byte to be written
*
- * @throws IOException If an error occurs attempting to write to this
- * FileOutputStream.
+ * @throws IOException
+ * If an error occurs attempting to write to this
+ * FileOutputStream.
*/
- @Override
+ @Override
public void write(int oneByte) throws IOException {
- openCheck();
+ openCheck();
byte[] byteArray = new byte[1];
- byteArray[0] = (byte)oneByte;
+ byteArray[0] = (byte) oneByte;
fileSystem.write(fd.descriptor, byteArray, 0, 1);
- }
+ }
- private synchronized void openCheck() throws IOException {
+ private synchronized void openCheck() throws IOException {
if (fd.descriptor < 0) {
throw new IOException();
}
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java Thu Jan 4 09:47:01 2007
@@ -35,9 +35,9 @@
* files and directories contained in that directory. If the pathname ends in
* "/-", it indicates all the files and directories in that directory
* <b>recursively</b>.
- *
*/
public final class FilePermission extends Permission implements Serializable {
+
private static final long serialVersionUID = 7930732926638008763L;
// canonical path of this permission
@@ -64,7 +64,6 @@
/**
* Constructs a new FilePermission with the path and actions specified.
*
- *
* @param path
* the path to apply the actions to.
* @param actions
@@ -81,7 +80,7 @@
throw new IllegalArgumentException(Msg.getString("K006d")); //$NON-NLS-1$
}
this.actions = toCanonicalActionString(pathActions);
-
+
if (path == null) {
throw new NullPointerException(Msg.getString("K006e")); //$NON-NLS-1$
}
@@ -348,8 +347,8 @@
*/
@Override
public int hashCode() {
- return (canonPath == null ?
- getName().hashCode() : canonPath.hashCode()) + mask;
+ return (canonPath == null ? getName().hashCode() : canonPath.hashCode())
+ + mask;
}
private void writeObject(ObjectOutputStream stream) throws IOException {
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermissionCollection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermissionCollection.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermissionCollection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermissionCollection.java Thu Jan 4 09:47:01 2007
@@ -15,8 +15,7 @@
* limitations under the License.
*/
-package java.io;
-
+package java.io;
import java.security.Permission;
import java.security.PermissionCollection;
@@ -27,56 +26,55 @@
* FilePermissionCollection is a class which holds a collection of
* FilePermission objects and can answer a boolean indicating whether or not a
* specific permissions is implied by a FilePermissionCollection.
- *
*/
-final class FilePermissionCollection extends PermissionCollection
- implements Serializable {
- private static final long serialVersionUID = 2202956749081564585L;
-
- Vector<Permission> permissions = new Vector<Permission>();
-
- /**
- * Construct a new FilePermissionCollection.
- */
- public FilePermissionCollection() {
- super();
- }
-
- /**
- * Add a permission Object to the permission collection.
- *
- * @see java.security.PermissionCollection#add(java.security.Permission)
- */
- @Override
+final class FilePermissionCollection extends PermissionCollection implements
+ Serializable {
+
+ private static final long serialVersionUID = 2202956749081564585L;
+
+ Vector<Permission> permissions = new Vector<Permission>();
+
+ /**
+ * Construct a new FilePermissionCollection.
+ */
+ public FilePermissionCollection() {
+ super();
+ }
+
+ /**
+ * Add a permission Object to the permission collection.
+ *
+ * @see java.security.PermissionCollection#add(java.security.Permission)
+ */
+ @Override
public void add(Permission permission) {
- if (!isReadOnly()) {
- if (permission instanceof FilePermission) {
- permissions.addElement(permission);
- } else {
- throw new IllegalArgumentException(permission.toString());
- }
- } else {
+ if (isReadOnly()) {
throw new IllegalStateException();
}
+ if (permission instanceof FilePermission) {
+ permissions.addElement(permission);
+ } else {
+ throw new IllegalArgumentException(permission.toString());
+ }
}
- /**
+ /**
* Answers an enumeration for the collection of permissions.
*
* @see java.security.PermissionCollection#elements()
*/
- @Override
+ @Override
public Enumeration<Permission> elements() {
- return permissions.elements();
- }
+ return permissions.elements();
+ }
- /**
- * Answers a boolean indicating whether or not this permissions collection
- * implies a specific <code>permission</code>.
- *
- * @see java.security.PermissionCollection#implies(java.security.Permission)
- */
- @Override
+ /**
+ * Answers a boolean indicating whether or not this permissions collection
+ * implies a specific <code>permission</code>.
+ *
+ * @see java.security.PermissionCollection#implies(java.security.Permission)
+ */
+ @Override
public boolean implies(Permission permission) {
if (permission instanceof FilePermission) {
FilePermission fp = (FilePermission) permission;
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileReader.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileReader.java Thu Jan 4 09:47:01 2007
@@ -17,7 +17,6 @@
package java.io;
-
/**
* FileReader is class for turning a file into a character Stream. Data read
* from the source is converted into characters. The encoding is assumed to
@@ -28,46 +27,45 @@
*/
public class FileReader extends InputStreamReader {
- /**
- * Construct a new FileReader on the given File <code>file</code>. If the
- * <code>file</code> specified cannot be found, throw a
- * FileNotFoundException.
- *
- * @param file
- * a File to be opened for reading characters from.
- *
- * @throws FileNotFoundException
- * if the file cannot be opened for reading.
- */
- public FileReader(File file) throws FileNotFoundException {
- super(new FileInputStream(file));
- }
-
- /**
- * Construct a new FileReader on the given FileDescriptor <code>fd</code>.
- * Since a previously opened FileDescriptor is passed as an argument, no
- * FileNotFoundException is thrown.
- *
- * @param fd
- * the previously opened file descriptor.
- */
- public FileReader(FileDescriptor fd) {
- super(new FileInputStream(fd));
- }
+ /**
+ * Construct a new FileReader on the given File <code>file</code>. If the
+ * <code>file</code> specified cannot be found, throw a
+ * FileNotFoundException.
+ *
+ * @param file
+ * a File to be opened for reading characters from.
+ *
+ * @throws FileNotFoundException
+ * if the file cannot be opened for reading.
+ */
+ public FileReader(File file) throws FileNotFoundException {
+ super(new FileInputStream(file));
+ }
- /**
- * Construct a new FileReader on the given file named <code>filename</code>.
- * If the <code>filename</code> specified cannot be found, throw a
- * FileNotFoundException.
- *
- * @param filename
- * an absolute or relative path specifying the file to open.
- *
- * @throws FileNotFoundException
- * if the filename cannot be opened for reading.
- */
- public FileReader(String filename) throws FileNotFoundException {
- super(new FileInputStream(filename));
- }
+ /**
+ * Construct a new FileReader on the given FileDescriptor <code>fd</code>.
+ * Since a previously opened FileDescriptor is passed as an argument, no
+ * FileNotFoundException is thrown.
+ *
+ * @param fd
+ * the previously opened file descriptor.
+ */
+ public FileReader(FileDescriptor fd) {
+ super(new FileInputStream(fd));
+ }
+ /**
+ * Construct a new FileReader on the given file named <code>filename</code>.
+ * If the <code>filename</code> specified cannot be found, throw a
+ * FileNotFoundException.
+ *
+ * @param filename
+ * an absolute or relative path specifying the file to open.
+ *
+ * @throws FileNotFoundException
+ * if the filename cannot be opened for reading.
+ */
+ public FileReader(String filename) throws FileNotFoundException {
+ super(new FileInputStream(filename));
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileWriter.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileWriter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FileWriter.java Thu Jan 4 09:47:01 2007
@@ -15,8 +15,7 @@
* limitations under the License.
*/
-package java.io;
-
+package java.io;
/**
* FileWriter is a class for writing characters out to a file. The default
@@ -27,76 +26,75 @@
*/
public class FileWriter extends OutputStreamWriter {
- /**
- * Creates a FileWriter using the File <code>file</code>.
- *
- * @param file
- * the non-null File to write bytes to.
- *
- * @throws IOException
- * If the given file is not found
- */
- public FileWriter(File file) throws IOException {
- super(new FileOutputStream(file));
- }
-
- /**
- * Creates a FileWriter using the File <code>file</code>. The parameter
- * <code>append</code> determines whether or not the file is opened and
- * appended to or just opened empty.
- *
- * @param file
- * the non-null File to write bytes to.
- * @param append
- * should the file be appened to or opened empty.
- *
- * @throws IOException
- * If the given file is not found
- */
- public FileWriter(File file, boolean append) throws IOException {
- super(new FileOutputStream(file, append));
- }
-
- /**
- * Creates a FileWriter using the existing FileDescriptor <code>fd</code>.
- *
- * @param fd
- * the non-null FileDescriptor to write bytes to.
- */
- public FileWriter(FileDescriptor fd) {
- super(new FileOutputStream(fd));
- }
-
- /**
- * Creates a FileWriter using the platform dependent <code>filename</code>.
- * See the class description for how characters are converted to bytes.
- *
- * @param filename
- * the non-null name of the file to write bytes to.
- *
- * @throws IOException
- * If the given file is not found
- */
- public FileWriter(String filename) throws IOException {
- super(new FileOutputStream(new File(filename)));
- }
-
- /**
- * Creates a FileWriter using the platform dependent <code>filename</code>.
- * See the class description for how characters are converted to bytes. The
- * parameter <code>append</code> determines whether or not the file is
- * opened and appended to or just opened empty.
- *
- * @param filename
- * the non-null name of the file to write bytes to.
- * @param append
- * should the file be appened to or opened empty.
- *
- * @throws IOException
- * If the given file is not found
- */
- public FileWriter(String filename, boolean append) throws IOException {
- super(new FileOutputStream(filename, append));
- }
-
+ /**
+ * Creates a FileWriter using the File <code>file</code>.
+ *
+ * @param file
+ * the non-null File to write bytes to.
+ *
+ * @throws IOException
+ * If the given file is not found
+ */
+ public FileWriter(File file) throws IOException {
+ super(new FileOutputStream(file));
+ }
+
+ /**
+ * Creates a FileWriter using the File <code>file</code>. The parameter
+ * <code>append</code> determines whether or not the file is opened and
+ * appended to or just opened empty.
+ *
+ * @param file
+ * the non-null File to write bytes to.
+ * @param append
+ * should the file be appened to or opened empty.
+ *
+ * @throws IOException
+ * If the given file is not found
+ */
+ public FileWriter(File file, boolean append) throws IOException {
+ super(new FileOutputStream(file, append));
+ }
+
+ /**
+ * Creates a FileWriter using the existing FileDescriptor <code>fd</code>.
+ *
+ * @param fd
+ * the non-null FileDescriptor to write bytes to.
+ */
+ public FileWriter(FileDescriptor fd) {
+ super(new FileOutputStream(fd));
+ }
+
+ /**
+ * Creates a FileWriter using the platform dependent <code>filename</code>.
+ * See the class description for how characters are converted to bytes.
+ *
+ * @param filename
+ * the non-null name of the file to write bytes to.
+ *
+ * @throws IOException
+ * If the given file is not found
+ */
+ public FileWriter(String filename) throws IOException {
+ super(new FileOutputStream(new File(filename)));
+ }
+
+ /**
+ * Creates a FileWriter using the platform dependent <code>filename</code>.
+ * See the class description for how characters are converted to bytes. The
+ * parameter <code>append</code> determines whether or not the file is
+ * opened and appended to or just opened empty.
+ *
+ * @param filename
+ * the non-null name of the file to write bytes to.
+ * @param append
+ * should the file be appened to or opened empty.
+ *
+ * @throws IOException
+ * If the given file is not found
+ */
+ public FileWriter(String filename, boolean append) throws IOException {
+ super(new FileOutputStream(filename, append));
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilenameFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilenameFilter.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilenameFilter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilenameFilter.java Thu Jan 4 09:47:01 2007
@@ -17,24 +17,24 @@
package java.io;
-
/**
- * FilenameFilter is an interface which declares methods for filtering file names
- * in the <code>list</code> method of File.
- *
- * @see File
- * @see File#list(FilenameFilter)
+ * FilenameFilter is an interface which declares methods for filtering file
+ * names in the <code>list</code> method of File.
+ *
+ * @see File
+ * @see File#list(FilenameFilter)
*/
public interface FilenameFilter {
-/**
- * Answers a boolean if a specific filename matches a filter.
- *
- * @param dir the directory in which the <code>filename</code> was found.
- * @param filename the name of the file in <code>dir</dir> to test.
- * @return boolean <code>true</code> if the filename matches the filter and can be included
- * in the list, <code>false</code> otherwise.
- */
-public abstract boolean accept(File dir, String filename);
-
+ /**
+ * Answers a boolean if a specific filename matches a filter.
+ *
+ * @param dir
+ * the directory in which the <code>filename</code> was found.
+ * @param filename
+ * the name of the file in <code>dir</dir> to test.
+ * @return boolean <code>true</code> if the filename matches the filter and can be included
+ * in the list, <code>false</code> otherwise.
+ */
+ public abstract boolean accept(File dir, String filename);
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterInputStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterInputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterInputStream.java Thu Jan 4 09:47:01 2007
@@ -15,8 +15,7 @@
* limitations under the License.
*/
-package java.io;
-
+package java.io;
/**
* FilteredInputStream is a class which takes an input stream and
@@ -28,171 +27,171 @@
*/
public class FilterInputStream extends InputStream {
- /**
- * The target InputStream which is being filtered.
- */
- protected InputStream in;
-
- /**
- * Constructs a new FilterInputStream on the InputStream <code>in</code>.
- * All reads are now filtered through this stream.
- *
- * @param in
- * The non-null InputStream to filter reads on.
- */
- protected FilterInputStream(InputStream in) {
- super();
- this.in = in;
- }
-
- /**
- * Answers a int representing the number of bytes that are available before
- * this FilterInputStream will block. This method returns the number of
- * bytes available in the target stream.
- *
- * @return the number of bytes available before blocking.
- *
- * @throws IOException
- * If an error occurs in this stream.
- */
- @Override
+ /**
+ * The target InputStream which is being filtered.
+ */
+ protected InputStream in;
+
+ /**
+ * Constructs a new FilterInputStream on the InputStream <code>in</code>.
+ * All reads are now filtered through this stream.
+ *
+ * @param in
+ * The non-null InputStream to filter reads on.
+ */
+ protected FilterInputStream(InputStream in) {
+ super();
+ this.in = in;
+ }
+
+ /**
+ * Answers a int representing the number of bytes that are available before
+ * this FilterInputStream will block. This method returns the number of
+ * bytes available in the target stream.
+ *
+ * @return the number of bytes available before blocking.
+ *
+ * @throws IOException
+ * If an error occurs in this stream.
+ */
+ @Override
public int available() throws IOException {
- return in.available();
- }
+ return in.available();
+ }
- /**
- * Close this FilterInputStream. This implementation closes the target
- * stream.
- *
- * @throws IOException
- * If an error occurs attempting to close this stream.
- */
- @Override
+ /**
+ * Close this FilterInputStream. This implementation closes the target
+ * stream.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this stream.
+ */
+ @Override
public void close() throws IOException {
- in.close();
- }
+ in.close();
+ }
- /**
- * Set a Mark position in this FilterInputStream. The parameter
- * <code>readLimit</code> indicates how many bytes can be read before a
- * mark is invalidated. Sending reset() will reposition the Stream back to
- * the marked position provided <code>readLimit</code> has not been
- * surpassed.
- * <p>
- * This implementation sets a mark in the target stream.
- *
- * @param readlimit
- * the number of bytes to be able to read before invalidating the
- * mark.
- */
- @Override
+ /**
+ * Set a Mark position in this FilterInputStream. The parameter
+ * <code>readLimit</code> indicates how many bytes can be read before a
+ * mark is invalidated. Sending reset() will reposition the Stream back to
+ * the marked position provided <code>readLimit</code> has not been
+ * surpassed.
+ * <p>
+ * This implementation sets a mark in the target stream.
+ *
+ * @param readlimit
+ * the number of bytes to be able to read before invalidating the
+ * mark.
+ */
+ @Override
public synchronized void mark(int readlimit) {
- in.mark(readlimit);
- }
+ in.mark(readlimit);
+ }
- /**
- * Answers a boolean indicating whether or not this FilterInputStream
- * supports mark() and reset(). This implementation answers whether or not
- * the target stream supports marking.
- *
- * @return <code>true</code> if mark() and reset() are supported,
- * <code>false</code> otherwise.
- */
- @Override
+ /**
+ * Answers a boolean indicating whether or not this FilterInputStream
+ * supports mark() and reset(). This implementation answers whether or not
+ * the target stream supports marking.
+ *
+ * @return <code>true</code> if mark() and reset() are supported,
+ * <code>false</code> otherwise.
+ */
+ @Override
public boolean markSupported() {
- return in.markSupported();
- }
+ return in.markSupported();
+ }
- /**
- * Reads a single byte from this FilterInputStream and returns the result as
- * an int. The low-order byte is returned or -1 of the end of stream was
- * encountered. This implementation returns a byte from the target stream.
- *
- * @return the byte read or -1 if end of stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- @Override
+ /**
+ * Reads a single byte from this FilterInputStream and returns the result as
+ * an int. The low-order byte is returned or -1 of the end of stream was
+ * encountered. This implementation returns a byte from the target stream.
+ *
+ * @return the byte read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ @Override
public int read() throws IOException {
- return in.read();
- }
+ return in.read();
+ }
- /**
- * Reads bytes from this FilterInputStream and stores them in byte array
- * <code>buffer</code>. Answer the number of bytes actually read or -1 if
- * no bytes were read and end of stream was encountered. This implementation
- * reads bytes from the target stream.
- *
+ /**
+ * Reads bytes from this FilterInputStream and stores them in byte array
+ * <code>buffer</code>. Answer the number of bytes actually read or -1 if
+ * no bytes were read and end of stream was encountered. This implementation
+ * reads bytes from the target stream.
+ *
* @param buffer
- * the byte array in which to store the read bytes.
- * @return the number of bytes actually read or -1 if end of stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- @Override
+ * the byte array in which to store the read bytes.
+ * @return the number of bytes actually read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ @Override
public int read(byte[] buffer) throws IOException {
- return read(buffer, 0, buffer.length);
- }
+ return read(buffer, 0, buffer.length);
+ }
- /**
- * Reads at most <code>count</code> bytes from this FilterInputStream and
- * stores them in byte array <code>buffer</code> starting at
- * <code>offset</code>. Answer the number of bytes actually read or -1 if
- * no bytes were read and end of stream was encountered. This implementation
- * reads bytes from the target stream.
- *
- * @param buffer
- * the byte array in which to store the read bytes.
- * @param offset
- * the offset in <code>buffer</code> to store the read bytes.
- * @param count
- * the maximum number of bytes to store in <code>buffer</code>.
- * @return the number of bytes actually read or -1 if end of stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- @Override
+ /**
+ * Reads at most <code>count</code> bytes from this FilterInputStream and
+ * stores them in byte array <code>buffer</code> starting at
+ * <code>offset</code>. Answer the number of bytes actually read or -1 if
+ * no bytes were read and end of stream was encountered. This implementation
+ * reads bytes from the target stream.
+ *
+ * @param buffer
+ * the byte array in which to store the read bytes.
+ * @param offset
+ * the offset in <code>buffer</code> to store the read bytes.
+ * @param count
+ * the maximum number of bytes to store in <code>buffer</code>.
+ * @return the number of bytes actually read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ @Override
public int read(byte[] buffer, int offset, int count) throws IOException {
- return in.read(buffer, offset, count);
- }
+ return in.read(buffer, offset, count);
+ }
- /**
- * Reset this FilterInputStream to the last marked location. If the
- * <code>readlimit</code> has been passed or no <code>mark</code> has
- * been set, throw IOException. This implementation resets the target
- * stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- @Override
+ /**
+ * Reset this FilterInputStream to the last marked location. If the
+ * <code>readlimit</code> has been passed or no <code>mark</code> has
+ * been set, throw IOException. This implementation resets the target
+ * stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ @Override
public synchronized void reset() throws IOException {
- in.reset();
- }
+ in.reset();
+ }
- /**
- * Skips <code>count</code> number of bytes in this InputStream.
- * Subsequent <code>read()</code>'s will not return these bytes unless
- * <code>reset()</code> is used. This implementation skips
- * <code>count</code> number of bytes in the target stream.
- *
- * @param count
- * the number of bytes to skip.
- * @return the number of bytes actually skipped.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- @Override
+ /**
+ * Skips <code>count</code> number of bytes in this InputStream.
+ * Subsequent <code>read()</code>'s will not return these bytes unless
+ * <code>reset()</code> is used. This implementation skips
+ * <code>count</code> number of bytes in the target stream.
+ *
+ * @param count
+ * the number of bytes to skip.
+ * @return the number of bytes actually skipped.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ @Override
public long skip(long count) throws IOException {
- return in.skip(count);
- }
+ return in.skip(count);
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterOutputStream.java Thu Jan 4 09:47:01 2007
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package java.io;
+package java.io;
import org.apache.harmony.luni.util.Msg;
-
/**
* FilteredOutputStream is a class which takes an output stream and
* <em>filters</em> the output in some way. The filtered view may be a
@@ -30,118 +29,118 @@
*/
public class FilterOutputStream extends OutputStream {
- /**
- * The target OutputStream for this filter.
- */
- protected OutputStream out;
-
- /**
- * Constructs a new FilterOutputStream on the OutputStream <code>out</code>.
- * All writes are now filtered through this stream.
- *
- * @param out
- * the target OutputStream to filter writes on.
- */
- public FilterOutputStream(OutputStream out) {
- this.out = out;
- }
-
- /**
- * Close this FilterOutputStream. This implementation closes the target
- * stream.
- *
- * @throws IOException
- * If an error occurs attempting to close this stream.
- */
- @Override
+ /**
+ * The target OutputStream for this filter.
+ */
+ protected OutputStream out;
+
+ /**
+ * Constructs a new FilterOutputStream on the OutputStream <code>out</code>.
+ * All writes are now filtered through this stream.
+ *
+ * @param out
+ * the target OutputStream to filter writes on.
+ */
+ public FilterOutputStream(OutputStream out) {
+ this.out = out;
+ }
+
+ /**
+ * Close this FilterOutputStream. This implementation closes the target
+ * stream.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this stream.
+ */
+ @Override
public void close() throws IOException {
- try {
- flush();
- } catch (IOException e) {
- }
- /* Make sure we clean up this stream if exception fires */
- out.close();
- }
-
- /**
- * Flush this FilterOutputStream to ensure all pending data is sent out to
- * the target OutputStream. This implementation flushes the target
- * OutputStream.
- *
- * @throws IOException
- * If an error occurs attempting to flush this
- * FilterOutputStream.
- */
- @Override
+ try {
+ flush();
+ } catch (IOException e) {
+ // Ignored
+ }
+ /* Make sure we clean up this stream if exception fires */
+ out.close();
+ }
+
+ /**
+ * Flush this FilterOutputStream to ensure all pending data is sent out to
+ * the target OutputStream. This implementation flushes the target
+ * OutputStream.
+ *
+ * @throws IOException
+ * If an error occurs attempting to flush this
+ * FilterOutputStream.
+ */
+ @Override
public void flush() throws IOException {
- out.flush();
- }
+ out.flush();
+ }
- /**
- * Writes the entire contents of the byte array <code>buffer</code> to
- * this FilterOutputStream. This implementation writes the
- * <code>buffer</code> to the target stream.
- *
- * @param buffer
- * the buffer to be written
- *
- * @throws IOException
- * If an error occurs attempting to write to this
- * FilterOutputStream.
- */
- @Override
+ /**
+ * Writes the entire contents of the byte array <code>buffer</code> to
+ * this FilterOutputStream. This implementation writes the
+ * <code>buffer</code> to the target stream.
+ *
+ * @param buffer
+ * the buffer to be written
+ *
+ * @throws IOException
+ * If an error occurs attempting to write to this
+ * FilterOutputStream.
+ */
+ @Override
public void write(byte buffer[]) throws IOException {
- write(buffer, 0, buffer.length);
- }
+ write(buffer, 0, buffer.length);
+ }
- /**
- * Writes <code>count</code> <code>bytes</code> from the byte array
- * <code>buffer</code> starting at <code>offset</code> to this
- * FilterOutputStream. This implementation writes the <code>buffer</code>
- * to the target OutputStream.
- *
- * @param buffer
- * the buffer to be written
- * @param offset
- * offset in buffer to get bytes
- * @param count
- * number of bytes in buffer to write
- *
- * @throws IOException
- * If an error occurs attempting to write to this
- * FilterOutputStream.
- * @throws IndexOutOfBoundsException
- * If offset or count are outside of bounds.
- */
- @Override
+ /**
+ * Writes <code>count</code> <code>bytes</code> from the byte array
+ * <code>buffer</code> starting at <code>offset</code> to this
+ * FilterOutputStream. This implementation writes the <code>buffer</code>
+ * to the target OutputStream.
+ *
+ * @param buffer
+ * the buffer to be written
+ * @param offset
+ * offset in buffer to get bytes
+ * @param count
+ * number of bytes in buffer to write
+ *
+ * @throws IOException
+ * If an error occurs attempting to write to this
+ * FilterOutputStream.
+ * @throws IndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ */
+ @Override
public void write(byte buffer[], int offset, int count) throws IOException {
- // avoid int overflow, check null buffer
- if (offset <= buffer.length && 0 <= offset && 0 <= count
- && count <= buffer.length - offset) {
- for (int i = 0; i < count; i++) {
- // Call write() instead of out.write() since subclasses could
- // override the write() method.
- write(buffer[offset + i]);
- }
- } else {
+ // avoid int overflow, force null buffer check first
+ if (offset > buffer.length || offset < 0 || count < 0
+ || count > buffer.length - offset) {
throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
- }
+ for (int i = 0; i < count; i++) {
+ // Call write() instead of out.write() since subclasses could
+ // override the write() method.
+ write(buffer[offset + i]);
+ }
+ }
- /**
- * Writes the specified byte <code>oneByte</code> to this
- * FilterOutputStream. Only the low order byte of <code>oneByte</code> is
- * written. This implementation writes the byte to the target OutputStream.
- *
- * @param oneByte
- * the byte to be written
- *
- * @throws IOException
- * If an error occurs attempting to write to this
- * FilterOutputStream.
- */
- @Override
+ /**
+ * Writes the specified byte <code>oneByte</code> to this
+ * FilterOutputStream. Only the low order byte of <code>oneByte</code> is
+ * written. This implementation writes the byte to the target OutputStream.
+ *
+ * @param oneByte
+ * the byte to be written
+ *
+ * @throws IOException
+ * If an error occurs attempting to write to this
+ * FilterOutputStream.
+ */
+ @Override
public void write(int oneByte) throws IOException {
- out.write(oneByte);
- }
+ out.write(oneByte);
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterReader.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterReader.java Thu Jan 4 09:47:01 2007
@@ -17,7 +17,6 @@
package java.io;
-
/**
* FilterReader is a class which takes a Reader and <em>filters</em> the input
* in some way. The filtered view may be a buffered view or one which
@@ -27,176 +26,174 @@
*/
public abstract class FilterReader extends Reader {
- /**
- * The target Reader which is being filtered.
- */
- protected Reader in;
-
- /**
- * Constructs a new FilterReader on the Reader <code>in</code>. All reads
- * are now filtered through this Reader.
- *
- * @param in
- * The non-null Reader to filter reads on.
- */
- protected FilterReader(Reader in) {
- super(in);
- this.in = in;
- }
-
- /**
- * Close this FilterReader. This implementation closes the target Reader.
- *
- * @throws IOException
- * If an error occurs attempting to close this Reader.
- */
- @Override
+ /**
+ * The target Reader which is being filtered.
+ */
+ protected Reader in;
+
+ /**
+ * Constructs a new FilterReader on the Reader <code>in</code>. All reads
+ * are now filtered through this Reader.
+ *
+ * @param in
+ * The non-null Reader to filter reads on.
+ */
+ protected FilterReader(Reader in) {
+ super(in);
+ this.in = in;
+ }
+
+ /**
+ * Close this FilterReader. This implementation closes the target Reader.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this Reader.
+ */
+ @Override
public void close() throws IOException {
- synchronized (lock) {
- in.close();
- }
- }
-
- /**
- * Set a Mark position in this FilterReader. The parameter
- * <code>readLimit</code> indicates how many characters can be read before
- * a mark is invalidated. Sending reset() will reposition the Reader back to
- * the marked position provided <code>readLimit</code> has not been
- * surpassed.
- * <p>
- * This implementation sets a mark in the target Reader.
- *
- * @param readlimit
- * the number of characters to be able to read before
- * invalidating the mark.
- *
- * @throws IOException
- * If an error occurs attempting mark this Reader.
- */
- @Override
+ synchronized (lock) {
+ in.close();
+ }
+ }
+
+ /**
+ * Set a Mark position in this FilterReader. The parameter
+ * <code>readLimit</code> indicates how many characters can be read before
+ * a mark is invalidated. Sending reset() will reposition the Reader back to
+ * the marked position provided <code>readLimit</code> has not been
+ * surpassed.
+ * <p>
+ * This implementation sets a mark in the target Reader.
+ *
+ * @param readlimit
+ * the number of characters to be able to read before
+ * invalidating the mark.
+ *
+ * @throws IOException
+ * If an error occurs attempting mark this Reader.
+ */
+ @Override
public synchronized void mark(int readlimit) throws IOException {
- synchronized (lock) {
- in.mark(readlimit);
- }
- }
-
- /**
- * Answers a boolean indicating whether or not this FilterReader supports
- * mark() and reset(). This implementation answers whether or not the target
- * Reader supports marking.
- *
- * @return indicates whether or not mark() and reset() are supported.
- */
- @Override
+ synchronized (lock) {
+ in.mark(readlimit);
+ }
+ }
+
+ /**
+ * Answers a boolean indicating whether or not this FilterReader supports
+ * mark() and reset(). This implementation answers whether or not the target
+ * Reader supports marking.
+ *
+ * @return indicates whether or not mark() and reset() are supported.
+ */
+ @Override
public boolean markSupported() {
- synchronized (lock) {
- return in.markSupported();
- }
- }
-
- /**
- * Reads a single char from this FilterReader and returns the result as an
- * int. The 2 lowest order bytes are returned or -1 of the end of reader was
- * encountered. This implementation returns a char from the target Reader.
- *
- * @return The byte read or -1 if end of reader.
- *
- * @throws IOException
- * If an error occurs attempting to read from this Reader.
- */
- @Override
+ synchronized (lock) {
+ return in.markSupported();
+ }
+ }
+
+ /**
+ * Reads a single char from this FilterReader and returns the result as an
+ * int. The 2 lowest order bytes are returned or -1 of the end of reader was
+ * encountered. This implementation returns a char from the target Reader.
+ *
+ * @return The byte read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If an error occurs attempting to read from this Reader.
+ */
+ @Override
public int read() throws IOException {
- synchronized (lock) {
- return in.read();
- }
- }
-
- /**
- * Reads at most <code>count</code> chars from this FilterReader and
- * stores them in char array <code>buffer</code> starting at offset
- * <code>offset</code>. Answer the number of chars actually read or -1 if
- * no chars were read and end of reader was encountered. This implementation
- * reads chars from the target reader.
- *
- * @param buffer
- * the char array in which to store the read chars.
- * @param offset
- * the offset in <code>buffer</code> to store the read chars.
- * @param count
- * the maximum number of chars to store in <code>buffer</code>.
- * @return the number of chars actually read or -1 if end of reader.
- *
- * @throws IOException
- * If an error occurs attempting to read from this Reader.
- */
- @Override
+ synchronized (lock) {
+ return in.read();
+ }
+ }
+
+ /**
+ * Reads at most <code>count</code> chars from this FilterReader and
+ * stores them in char array <code>buffer</code> starting at offset
+ * <code>offset</code>. Answer the number of chars actually read or -1 if
+ * no chars were read and end of reader was encountered. This implementation
+ * reads chars from the target reader.
+ *
+ * @param buffer
+ * the char array in which to store the read chars.
+ * @param offset
+ * the offset in <code>buffer</code> to store the read chars.
+ * @param count
+ * the maximum number of chars to store in <code>buffer</code>.
+ * @return the number of chars actually read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If an error occurs attempting to read from this Reader.
+ */
+ @Override
public int read(char[] buffer, int offset, int count) throws IOException {
- synchronized (lock) {
- return in.read(buffer, offset, count);
- }
- }
-
- /**
- * Answers a <code>boolean</code> indicating whether or not this Reader is
- * ready to be read without blocking. If the result is <code>true</code>,
- * the next <code>read()</code> will not block. If the result is
- * <code>false</code> this Reader may or may not block when
- * <code>read()</code> is sent.
- *
- * @return <code>true</code> if the receiver will not block when
- * <code>read()</code> is called, <code>false</code> if unknown
- * or blocking will occur.
- *
- * @throws IOException
- * If the Reader is already closed or some other IO error
- * occurs.
- */
-
- @Override
+ synchronized (lock) {
+ return in.read(buffer, offset, count);
+ }
+ }
+
+ /**
+ * Answers a <code>boolean</code> indicating whether or not this Reader is
+ * ready to be read without blocking. If the result is <code>true</code>,
+ * the next <code>read()</code> will not block. If the result is
+ * <code>false</code> this Reader may or may not block when
+ * <code>read()</code> is sent.
+ *
+ * @return <code>true</code> if the receiver will not block when
+ * <code>read()</code> is called, <code>false</code> if unknown
+ * or blocking will occur.
+ *
+ * @throws IOException
+ * If the Reader is already closed or some other IO error
+ * occurs.
+ */
+ @Override
public boolean ready() throws IOException {
- synchronized (lock) {
- return in.ready();
- }
- }
-
- /**
- * Reset this Readers position to the last <code>mark()</code> location.
- * Invocations of <code>read()/skip()</code> will occur from this new
- * location. If this Reader was not marked, the implementation of
- * <code>reset()</code> is implementation specific. See the comment for
- * the specific Reader subclass for implementation details. The default
- * action is to throw <code>IOException</code>.
- *
- * @throws IOException
- * if a problem occurred or the target Reader does not support
- * <code>mark()/reset()</code>.
- */
- @Override
+ synchronized (lock) {
+ return in.ready();
+ }
+ }
+
+ /**
+ * Reset this Readers position to the last <code>mark()</code> location.
+ * Invocations of <code>read()/skip()</code> will occur from this new
+ * location. If this Reader was not marked, the implementation of
+ * <code>reset()</code> is implementation specific. See the comment for
+ * the specific Reader subclass for implementation details. The default
+ * action is to throw <code>IOException</code>.
+ *
+ * @throws IOException
+ * if a problem occurred or the target Reader does not support
+ * <code>mark()/reset()</code>.
+ */
+ @Override
public void reset() throws IOException {
- synchronized (lock) {
- in.reset();
- }
- }
-
- /**
- * Skips <code>count</code> number of characters in this Reader.
- * Subsequent <code>read()</code>'s will not return these characters
- * unless <code>reset()</code> is used. The default implementation is to
- * skip chars in the filtered Reader.
- *
- * @param count
- * the maximum number of characters to skip.
- * @return the number of characters actually skipped.
- *
- * @throws IOException
- * If the Reader is already closed or some other IO error
- * occurs.
- */
- @Override
+ synchronized (lock) {
+ in.reset();
+ }
+ }
+
+ /**
+ * Skips <code>count</code> number of characters in this Reader.
+ * Subsequent <code>read()</code>'s will not return these characters
+ * unless <code>reset()</code> is used. The default implementation is to
+ * skip chars in the filtered Reader.
+ *
+ * @param count
+ * the maximum number of characters to skip.
+ * @return the number of characters actually skipped.
+ *
+ * @throws IOException
+ * If the Reader is already closed or some other IO error
+ * occurs.
+ */
+ @Override
public long skip(long count) throws IOException {
- synchronized (lock) {
- return in.skip(count);
- }
- }
-
+ synchronized (lock) {
+ return in.skip(count);
+ }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterWriter.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterWriter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilterWriter.java Thu Jan 4 09:47:01 2007
@@ -17,7 +17,6 @@
package java.io;
-
/**
* FilterWriter is a class which takes a Writer and <em>filters</em> the
* output in some way. The filtered view may be a buffered output or one which
@@ -27,115 +26,114 @@
*/
public abstract class FilterWriter extends Writer {
- /**
- * The Writer being filtered.
- */
- protected Writer out;
-
- /**
- * Constructs a new FilterWriter on the Writer <code>out</code>. All
- * writes are now filtered through this Writer.
- *
- * @param out
- * the target Writer to filter writes on.
- */
- protected FilterWriter(Writer out) {
- super(out);
- this.out = out;
- }
-
- /**
- * Close this FilterWriter. Closes the Writer <code>out</code> by default.
- * This will close any downstream Writers as well. Any additional processing
- * required by concrete subclasses should be provided in their own
- * <code>close</code> implementation.
- *
- * @throws java.io.IOException
- * If an error occurs attempting to close this FilterWriter.
- */
- @Override
+ /**
+ * The Writer being filtered.
+ */
+ protected Writer out;
+
+ /**
+ * Constructs a new FilterWriter on the Writer <code>out</code>. All
+ * writes are now filtered through this Writer.
+ *
+ * @param out
+ * the target Writer to filter writes on.
+ */
+ protected FilterWriter(Writer out) {
+ super(out);
+ this.out = out;
+ }
+
+ /**
+ * Close this FilterWriter. Closes the Writer <code>out</code> by default.
+ * This will close any downstream Writers as well. Any additional processing
+ * required by concrete subclasses should be provided in their own
+ * <code>close</code> implementation.
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to close this FilterWriter.
+ */
+ @Override
public void close() throws IOException {
- synchronized (lock) {
- out.close();
- }
- }
-
- /**
- * Flush this FilteredWriter to ensure all pending data is sent out to the
- * target Writer. This implementation flushes the target Writer.
- *
- * @throws java.io.IOException
- * If an error occurs attempting to flush this FilterWriter.
- */
- @Override
+ synchronized (lock) {
+ out.close();
+ }
+ }
+
+ /**
+ * Flush this FilteredWriter to ensure all pending data is sent out to the
+ * target Writer. This implementation flushes the target Writer.
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to flush this FilterWriter.
+ */
+ @Override
public void flush() throws IOException {
- synchronized (lock) {
- out.flush();
- }
- }
-
- /**
- * Writes <code>count</code> <code>chars</code> from the char array
- * <code>buffer</code> starting at offset <code>index</code> to this
- * FilterWriter. This implementation writes the <code>buffer</code> to the
- * target Writer.
- *
- * @param buffer
- * the buffer to be written
- * @param offset
- * offset in buffer to get chars
- * @param count
- * number of chars in buffer to write
- *
- * @throws java.io.IOException
- * If an error occurs attempting to write to this FilterWriter.
- */
- @Override
+ synchronized (lock) {
+ out.flush();
+ }
+ }
+
+ /**
+ * Writes <code>count</code> <code>chars</code> from the char array
+ * <code>buffer</code> starting at offset <code>index</code> to this
+ * FilterWriter. This implementation writes the <code>buffer</code> to the
+ * target Writer.
+ *
+ * @param buffer
+ * the buffer to be written
+ * @param offset
+ * offset in buffer to get chars
+ * @param count
+ * number of chars in buffer to write
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to write to this FilterWriter.
+ */
+ @Override
public void write(char buffer[], int offset, int count) throws IOException {
- synchronized (lock) {
- out.write(buffer, offset, count);
- }
- }
-
- /**
- * Writes the specified char <code>oneChar</code> to this FilterWriter.
- * Only the 2 low order bytes of <code>oneChar</code> is written. This
- * implementation writes the char to the target Writer.
- *
- * @param oneChar
- * the char to be written
- *
- * @throws java.io.IOException
- * If an error occurs attempting to write to this FilterWriter.
- */
- @Override
+ synchronized (lock) {
+ out.write(buffer, offset, count);
+ }
+ }
+
+ /**
+ * Writes the specified char <code>oneChar</code> to this FilterWriter.
+ * Only the 2 low order bytes of <code>oneChar</code> is written. This
+ * implementation writes the char to the target Writer.
+ *
+ * @param oneChar
+ * the char to be written
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to write to this FilterWriter.
+ */
+ @Override
public void write(int oneChar) throws IOException {
- synchronized (lock) {
- out.write(oneChar);
- }
- }
-
- /**
- * Writes <code>count</code> <code>chars</code> from the String
- * <code>str</code> starting at offset <code>index</code> to this
- * FilterWriter. This implementation writes the <code>str</code> to the
- * target Writer.
- *
- * @param str
- * the String to be written.
- * @param offset
- * offset in str to get chars.
- * @param count
- * number of chars in str to write.
- *
- * @throws java.io.IOException
- * If an error occurs attempting to write to this FilterWriter.
- */
- @Override
+ synchronized (lock) {
+ out.write(oneChar);
+ }
+ }
+
+ /**
+ * Writes <code>count</code> <code>chars</code> from the String
+ * <code>str</code> starting at offset <code>index</code> to this
+ * FilterWriter. This implementation writes the <code>str</code> to the
+ * target Writer.
+ *
+ * @param str
+ * the String to be written.
+ * @param offset
+ * offset in str to get chars.
+ * @param count
+ * number of chars in str to write.
+ *
+ * @throws java.io.IOException
+ * If an error occurs attempting to write to this FilterWriter.
+ */
+ @Override
public void write(String str, int offset, int count) throws IOException {
- synchronized (lock) {
- out.write(str, offset, count);
- }
- }
-
+ synchronized (lock) {
+ out.write(str, offset, count);
+ }
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Flushable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Flushable.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Flushable.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Flushable.java Thu Jan 4 09:47:01 2007
@@ -30,7 +30,8 @@
* output.
* </p>
*
- * @throws IOException if there are any issues writing the data.
+ * @throws IOException
+ * if there are any issues writing the data.
*/
void flush() throws IOException;
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/IOException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/IOException.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/IOException.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/IOException.java Thu Jan 4 09:47:01 2007
@@ -17,33 +17,29 @@
package java.io;
-
/**
* This IO exception is thrown when a program encounters some sort I/O error.
* Details may be specified in the constructor or by one of the subclasses.
- *
-
*/
public class IOException extends Exception {
private static final long serialVersionUID = 7818375828146090155L;
-
- /**
- * Constructs a new instance of this class with its walkback filled in.
- */
- public IOException() {
- super();
- }
- /**
- * Constructs a new instance of this class with its walkback and message
- * filled in.
- *
- * @param detailMessage
- * The detail message for the exception.
- */
- public IOException(String detailMessage) {
- super(detailMessage);
- }
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public IOException() {
+ super();
+ }
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public IOException(String detailMessage) {
+ super(detailMessage);
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java?view=diff&rev=492652&r1=492651&r2=492652
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStream.java Thu Jan 4 09:47:01 2007
@@ -15,8 +15,7 @@
* limitations under the License.
*/
-package java.io;
-
+package java.io;
/**
* InputStream is an abstract class for all byte input streams. It provides
@@ -26,188 +25,195 @@
*/
public abstract class InputStream extends Object implements Closeable {
- private static byte[] skipBuf;
+ private static byte[] skipBuf;
- /**
- * This constructor does nothing interesting. Provided for signature
- * compatibility.
- */
- public InputStream() {
- /* empty */
- }
-
- /**
- * Answers a int representing then number of bytes that are available before
- * this InputStream will block. This method always returns 0. Subclasses
- * should override and indicate the correct number of bytes available.
- *
- * @return the number of bytes available before blocking.
- *
- * @throws IOException
- * If an error occurs in this InputStream.
- */
- public int available() throws IOException {
- return 0;
- }
-
- /**
- * Close the InputStream. Concrete implementations of this class should free
- * any resources during close. This implementation does nothing.
- *
- * @throws IOException
- * If an error occurs attempting to close this InputStream.
- */
- public void close() throws IOException {
- /* empty */
- }
-
- /**
- * Set a Mark position in this InputStream. The parameter
- * <code>readLimit</code> indicates how many bytes can be read before a
- * mark is invalidated. Sending reset() will reposition the Stream back to
- * the marked position provided <code>readLimit</code> has not been
- * surpassed.
- * <p>
- * This default implementation does nothing and concrete subclasses must
- * provide their own implementations.
- *
- * @param readlimit
- * the number of bytes to be able to read before invalidating the
- * mark.
- */
- public void mark(int readlimit) {
- /* empty */
- }
-
- /**
- * Answers a boolean indicating whether or not this InputStream supports
- * mark() and reset(). This class provides a default implementation which
- * answers false.
- *
- * @return <code>true</code> if mark() and reset() are supported,
- * <code>false</code> otherwise.
- */
- public boolean markSupported() {
- return false;
- }
-
- /**
- * Reads a single byte from this InputStream and returns the result as an
- * int. The low-order byte is returned or -1 of the end of stream was
- * encountered. This abstract implementation must be provided by concrete
- * subclasses.
- *
- * @return the byte read or -1 if end of stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- public abstract int read() throws IOException;
-
- /**
- * Reads bytes from the Stream and stores them in byte array <code>b</code>.
- * Answer the number of bytes actually read or -1 if no bytes were read and
- * end of stream was encountered.
- *
- * @param b
- * the byte array in which to store the read bytes.
- * @return the number of bytes actually read or -1 if end of stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- public int read(byte b[]) throws IOException {
- return read(b, 0, b.length);
- }
-
- /**
- * Reads at most <code>length</code> bytes from the Stream and stores them
- * in byte array <code>b</code> starting at <code>offset</code>. Answer
- * the number of bytes actually read or -1 if no bytes were read and end of
- * stream was encountered.
- *
- * @param b
- * the byte array in which to store the read bytes.
- * @param offset
- * the offset in <code>b</code> to store the read bytes.
- * @param length
- * the maximum number of bytes to store in <code>b</code>.
- * @return the number of bytes actually read or -1 if end of stream.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- public int read(byte b[], int offset, int length) throws IOException {
- // avoid int overflow, check null b
- if (offset <= b.length && 0 <= offset && 0 <= length
- && length <= b.length - offset) {
- for (int i = 0; i < length; i++) {
- int c;
- try {
- if ((c = read()) == -1)
- return i == 0 ? -1 : i;
- } catch (IOException e) {
- if (i != 0)
- return i;
- throw e;
- }
- b[offset + i] = (byte) c;
- }
- return length;
- }
- throw new ArrayIndexOutOfBoundsException();
- }
-
- /**
- * Reset this InputStream to the last marked location. If the
- * <code>readlimit</code> has been passed or no <code>mark</code> has
- * been set, throw IOException. This implementation throws IOException and
- * concrete subclasses should provide proper implementations.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- public synchronized void reset() throws IOException {
- throw new IOException();
- }
-
- /**
- * Skips <code>n</code> number of bytes in this InputStream. Subsequent
- * <code>read()</code>'s will not return these bytes unless
- * <code>reset()</code> is used. This method may perform multiple reads to
- * read <code>n</code> bytes. This default implementation reads
- * <code>n</code> bytes into a temporary buffer. Concrete subclasses
- * should provide their own implementation.
- *
- * @param n
- * the number of bytes to skip.
- * @return the number of bytes actually skipped.
- *
- * @throws IOException
- * If the stream is already closed or another IOException
- * occurs.
- */
- public long skip(long n) throws IOException {
- if (n <= 0)
- return 0;
- long skipped = 0;
- int toRead = n < 4096 ? (int) n : 4096;
- if (skipBuf == null || skipBuf.length < toRead)
- skipBuf = new byte[toRead];
- while (skipped < n) {
- int read = read(skipBuf, 0, toRead);
- if (read == -1)
- return skipped;
- skipped += read;
- if (read < toRead)
- return skipped;
- if (n - skipped < toRead)
- toRead = (int) (n - skipped);
- }
- return skipped;
- }
+ /**
+ * This constructor does nothing interesting. Provided for signature
+ * compatibility.
+ */
+ public InputStream() {
+ /* empty */
+ }
+
+ /**
+ * Answers a int representing then number of bytes that are available before
+ * this InputStream will block. This method always returns 0. Subclasses
+ * should override and indicate the correct number of bytes available.
+ *
+ * @return the number of bytes available before blocking.
+ *
+ * @throws IOException
+ * If an error occurs in this InputStream.
+ */
+ public int available() throws IOException {
+ return 0;
+ }
+
+ /**
+ * Close the InputStream. Concrete implementations of this class should free
+ * any resources during close. This implementation does nothing.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this InputStream.
+ */
+ public void close() throws IOException {
+ /* empty */
+ }
+
+ /**
+ * Set a Mark position in this InputStream. The parameter
+ * <code>readLimit</code> indicates how many bytes can be read before a
+ * mark is invalidated. Sending reset() will reposition the Stream back to
+ * the marked position provided <code>readLimit</code> has not been
+ * surpassed.
+ * <p>
+ * This default implementation does nothing and concrete subclasses must
+ * provide their own implementations.
+ *
+ * @param readlimit
+ * the number of bytes to be able to read before invalidating the
+ * mark.
+ */
+ public void mark(int readlimit) {
+ /* empty */
+ }
+
+ /**
+ * Answers a boolean indicating whether or not this InputStream supports
+ * mark() and reset(). This class provides a default implementation which
+ * answers false.
+ *
+ * @return <code>true</code> if mark() and reset() are supported,
+ * <code>false</code> otherwise.
+ */
+ public boolean markSupported() {
+ return false;
+ }
+
+ /**
+ * Reads a single byte from this InputStream and returns the result as an
+ * int. The low-order byte is returned or -1 of the end of stream was
+ * encountered. This abstract implementation must be provided by concrete
+ * subclasses.
+ *
+ * @return the byte read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public abstract int read() throws IOException;
+
+ /**
+ * Reads bytes from the Stream and stores them in byte array <code>b</code>.
+ * Answer the number of bytes actually read or -1 if no bytes were read and
+ * end of stream was encountered.
+ *
+ * @param b
+ * the byte array in which to store the read bytes.
+ * @return the number of bytes actually read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public int read(byte b[]) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ /**
+ * Reads at most <code>length</code> bytes from the Stream and stores them
+ * in byte array <code>b</code> starting at <code>offset</code>. Answer
+ * the number of bytes actually read or -1 if no bytes were read and end of
+ * stream was encountered.
+ *
+ * @param b
+ * the byte array in which to store the read bytes.
+ * @param offset
+ * the offset in <code>b</code> to store the read bytes.
+ * @param length
+ * the maximum number of bytes to store in <code>b</code>.
+ * @return the number of bytes actually read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public int read(byte b[], int offset, int length) throws IOException {
+ // avoid int overflow, check null b
+ if (offset < 0 || offset > b.length || length < 0
+ || length > b.length - offset) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ for (int i = 0; i < length; i++) {
+ int c;
+ try {
+ if ((c = read()) == -1) {
+ return i == 0 ? -1 : i;
+ }
+ } catch (IOException e) {
+ if (i != 0) {
+ return i;
+ }
+ throw e;
+ }
+ b[offset + i] = (byte) c;
+ }
+ return length;
+ }
+
+ /**
+ * Reset this InputStream to the last marked location. If the
+ * <code>readlimit</code> has been passed or no <code>mark</code> has
+ * been set, throw IOException. This implementation throws IOException and
+ * concrete subclasses should provide proper implementations.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public synchronized void reset() throws IOException {
+ throw new IOException();
+ }
+
+ /**
+ * Skips <code>n</code> number of bytes in this InputStream. Subsequent
+ * <code>read()</code>'s will not return these bytes unless
+ * <code>reset()</code> is used. This method may perform multiple reads to
+ * read <code>n</code> bytes. This default implementation reads
+ * <code>n</code> bytes into a temporary buffer. Concrete subclasses
+ * should provide their own implementation.
+ *
+ * @param n
+ * the number of bytes to skip.
+ * @return the number of bytes actually skipped.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public long skip(long n) throws IOException {
+ if (n <= 0) {
+ return 0;
+ }
+ long skipped = 0;
+ int toRead = n < 4096 ? (int) n : 4096;
+ if (skipBuf == null || skipBuf.length < toRead) {
+ skipBuf = new byte[toRead];
+ }
+ while (skipped < n) {
+ int read = read(skipBuf, 0, toRead);
+ if (read == -1) {
+ return skipped;
+ }
+ skipped += read;
+ if (read < toRead) {
+ return skipped;
+ }
+ if (n - skipped < toRead) {
+ toRead = (int) (n - skipped);
+ }
+ }
+ return skipped;
+ }
}