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

Print this page
rev 6099 : [mq]: io-trace

*** 25,34 **** --- 25,36 ---- 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,65 **** --- 58,72 ---- * 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,207 **** throw new NullPointerException(); } this.fd = new FileDescriptor(); fd.attach(this); this.append = append; ! open(name, append); } /** * Creates a file output stream to write to the specified file --- 204,214 ---- 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,242 **** --- 240,250 ---- } if (security != null) { security.checkWrite(fdObj); } this.fd = fdObj; + this.path = null; this.append = false; fd.attach(this); }
*** 263,273 **** --- 271,288 ---- * * @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,296 **** --- 301,318 ---- * * @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,309 **** --- 321,338 ---- * @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,381 **** * @spec JSR-51 */ public FileChannel getChannel() { synchronized (this) { if (channel == null) { ! channel = FileChannelImpl.open(fd, false, true, append, this); } return channel; } } --- 400,410 ---- * @spec JSR-51 */ public FileChannel getChannel() { synchronized (this) { if (channel == null) { ! channel = FileChannelImpl.open(fd, path, false, true, append, this); } return channel; } }