src/share/classes/java/io/FileOutputStream.java

Print this page
rev 6052 : [mq]: jdk.patch

@@ -25,10 +25,11 @@
 
 package java.io;
 
 import java.nio.channels.FileChannel;
 import sun.nio.ch.FileChannelImpl;
+import sun.misc.IoTrace;
 
 
 /**
  * A file output stream is an output stream for writing data to a
  * <code>File</code> or to a <code>FileDescriptor</code>. Whether or not

@@ -56,10 +57,15 @@
      * The system dependent file descriptor.
      */
     private final FileDescriptor fd;
 
     /**
+     * The path of the referenced file (null if there is no file)
+     */
+    private final String path;
+
+    /**
      * True if the file is opened for append.
      */
     private final boolean append;
 
     /**

@@ -197,11 +203,11 @@
             throw new NullPointerException();
         }
         this.fd = new FileDescriptor();
         fd.attach(this);
         this.append = append;
-
+        this.path = name;
         open(name, append);
     }
 
     /**
      * Creates a file output stream to write to the specified file

@@ -233,10 +239,11 @@
         }
         if (security != null) {
             security.checkWrite(fdObj);
         }
         this.fd = fdObj;
+        this.path = null;
         this.append = false;
 
         fd.attach(this);
     }
 

@@ -263,11 +270,13 @@
      *
      * @param      b   the byte to be written.
      * @exception  IOException  if an I/O error occurs.
      */
     public void write(int b) throws IOException {
+        Object traceHandle = IoTrace.fileWriteBegin(path);
         write(b, append);
+        IoTrace.fileWriteEnd(traceHandle,  1);
     }
 
     /**
      * Writes a sub array as a sequence of bytes.
      * @param b the data to be written

@@ -286,11 +295,13 @@
      *
      * @param      b   the data.
      * @exception  IOException  if an I/O error occurs.
      */
     public void write(byte b[]) throws IOException {
+        Object traceHandle = IoTrace.fileWriteBegin(path);
         writeBytes(b, 0, b.length, append);
+        IoTrace.fileWriteEnd(traceHandle,  b.length);
     }
 
     /**
      * Writes <code>len</code> bytes from the specified byte array
      * starting at offset <code>off</code> to this file output stream.

@@ -299,11 +310,13 @@
      * @param      off   the start offset in the data.
      * @param      len   the number of bytes to write.
      * @exception  IOException  if an I/O error occurs.
      */
     public void write(byte b[], int off, int len) throws IOException {
+        Object traceHandle = IoTrace.fileWriteBegin(path);
         writeBytes(b, off, len, append);
+        IoTrace.fileWriteEnd(traceHandle,  len);
     }
 
     /**
      * Closes this file output stream and releases any system resources
      * associated with this stream. This file output stream may no longer

@@ -371,11 +384,11 @@
      * @spec JSR-51
      */
     public FileChannel getChannel() {
         synchronized (this) {
             if (channel == null) {
-                channel = FileChannelImpl.open(fd, false, true, append, this);
+                channel = FileChannelImpl.open(fd, path, false, true, append, this);
             }
             return channel;
         }
     }