6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
authormartin
Mon, 10 Mar 2008 14:32:51 -0700
changeset 46 ddf5deb2a633
parent 45 307f564057c1
child 47 c8f0e41aea68
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code Reviewed-by: alanb, iris
jdk/src/share/classes/java/io/FileInputStream.java
jdk/src/share/classes/java/io/FileOutputStream.java
--- a/jdk/src/share/classes/java/io/FileInputStream.java	Mon Mar 10 14:32:51 2008 -0700
+++ b/jdk/src/share/classes/java/io/FileInputStream.java	Mon Mar 10 14:32:51 2008 -0700
@@ -48,15 +48,15 @@
 class FileInputStream extends InputStream
 {
     /* File Descriptor - handle to the open file */
-    private FileDescriptor fd;
+    private final FileDescriptor fd;
 
     private FileChannel channel = null;
 
-    private Object closeLock = new Object();
+    private final Object closeLock = new Object();
     private volatile boolean closed = false;
 
-    private static ThreadLocal<Boolean> runningFinalize =
-                                new ThreadLocal<Boolean>();
+    private static final ThreadLocal<Boolean> runningFinalize =
+        new ThreadLocal<Boolean>();
 
     private static boolean isRunningFinalize() {
         Boolean val;
@@ -151,7 +151,7 @@
      * is thrown.
      * <p>
      * This constructor does not throw an exception if <code>fdObj</code>
-     * is {link java.io.FileDescriptor#valid() invalid}.
+     * 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.
      *
@@ -389,7 +389,7 @@
      * @see        java.io.FileInputStream#close()
      */
     protected void finalize() throws IOException {
-        if ((fd != null) &&  (fd != fd.in)) {
+        if ((fd != null) &&  (fd != FileDescriptor.in)) {
 
             /*
              * Finalizer should not release the FileDescriptor if another
--- a/jdk/src/share/classes/java/io/FileOutputStream.java	Mon Mar 10 14:32:51 2008 -0700
+++ b/jdk/src/share/classes/java/io/FileOutputStream.java	Mon Mar 10 14:32:51 2008 -0700
@@ -52,20 +52,18 @@
 class FileOutputStream extends OutputStream
 {
     /**
-     * The system dependent file descriptor. The value is
-     * 1 more than actual file descriptor. This means that
-     * the default value 0 indicates that the file is not open.
+     * The system dependent file descriptor.
      */
-    private FileDescriptor fd;
+    private final FileDescriptor fd;
 
     private FileChannel channel= null;
 
     private boolean append = false;
 
-    private Object closeLock = new Object();
+    private final Object closeLock = new Object();
     private volatile boolean closed = false;
-    private static ThreadLocal<Boolean> runningFinalize =
-                                        new ThreadLocal<Boolean>();
+    private static final ThreadLocal<Boolean> runningFinalize =
+        new ThreadLocal<Boolean>();
 
     private static boolean isRunningFinalize() {
         Boolean val;
@@ -75,7 +73,7 @@
     }
 
     /**
-     * Creates an output file stream to write to the file with the
+     * Creates a file output stream to write to the file with the
      * specified name. A new <code>FileDescriptor</code> object is
      * created to represent this file connection.
      * <p>
@@ -100,8 +98,8 @@
     }
 
     /**
-     * Creates an output file stream to write to the file with the specified
-     * <code>name</code>.  If the second argument is <code>true</code>, then
+     * Creates a file output stream to write to the file with the specified
+     * name.  If the second argument is <code>true</code>, then
      * bytes will be written to the end of the file rather than the beginning.
      * A new <code>FileDescriptor</code> object is created to represent this
      * file connection.
@@ -211,7 +209,7 @@
     }
 
     /**
-     * Creates an output file stream to write to the specified file
+     * Creates a file output stream to write to the specified file
      * descriptor, which represents an existing connection to an actual
      * file in the file system.
      * <p>
@@ -223,7 +221,7 @@
      * is thrown.
      * <p>
      * This constructor does not throw an exception if <code>fdObj</code>
-     * is {link java.io.FileDescriptor#valid() invalid}.
+     * 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.
      *
@@ -408,7 +406,7 @@
      */
     protected void finalize() throws IOException {
         if (fd != null) {
-            if (fd == fd.out || fd == fd.err) {
+            if (fd == FileDescriptor.out || fd == FileDescriptor.err) {
                 flush();
             } else {