src/share/classes/java/io/FileOutputStream.java
Print this page
rev 6099 : [mq]: io-trace
@@ -25,10 +25,12 @@
package java.io;
import java.nio.channels.FileChannel;
import sun.nio.ch.FileChannelImpl;
+import sun.misc.IoTrace;
+import sun.misc.IoTraceContext;
/**
* 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 +58,15 @@
* The system dependent file descriptor.
*/
private final FileDescriptor fd;
/**
+ * The path of the referenced file (null if the stream is created with a file descriptor)
+ */
+ private final String path;
+
+ /**
* True if the file is opened for append.
*/
private final boolean append;
/**
@@ -197,11 +204,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 +240,11 @@
}
if (security != null) {
security.checkWrite(fdObj);
}
this.fd = fdObj;
+ this.path = null;
this.append = false;
fd.attach(this);
}
@@ -263,11 +271,18 @@
*
* @param b the byte to be written.
* @exception IOException if an I/O error occurs.
*/
public void write(int b) throws IOException {
+ IoTraceContext traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
write(b, append);
+ bytesWritten = 1;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
* Writes a sub array as a sequence of bytes.
* @param b the data to be written
@@ -286,11 +301,18 @@
*
* @param b the data.
* @exception IOException if an I/O error occurs.
*/
public void write(byte b[]) throws IOException {
+ IoTraceContext traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
writeBytes(b, 0, b.length, append);
+ bytesWritten = b.length;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this file output stream.
@@ -299,11 +321,18 @@
* @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 {
+ IoTraceContext traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
writeBytes(b, off, len, append);
+ bytesWritten = len;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
* Closes this file output stream and releases any system resources
* associated with this stream. This file output stream may no longer
@@ -371,11 +400,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;
}
}