src/share/classes/java/io/FileInputStream.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 <code>FileInputStream</code> obtains input bytes
* from a file in a file system. What files
@@ -49,10 +50,13 @@
class FileInputStream extends InputStream
{
/* File Descriptor - handle to the open file */
private final FileDescriptor fd;
+ /* The path of the referenced file (null if there is no file) */
+ private final String path;
+
private FileChannel channel = null;
private final Object closeLock = new Object();
private volatile boolean closed = false;
@@ -123,10 +127,11 @@
if (name == null) {
throw new NullPointerException();
}
fd = new FileDescriptor();
fd.attach(this);
+ this.path = name;
open(name);
}
/**
* Creates a <code>FileInputStream</code> by using the file descriptor
@@ -159,10 +164,11 @@
}
if (security != null) {
security.checkRead(fdObj);
}
fd = fdObj;
+ path = null;
/*
* FileDescriptor is being shared by streams.
* Register this stream with FileDescriptor tracker.
*/
@@ -181,11 +187,18 @@
*
* @return the next byte of data, or <code>-1</code> if the end of the
* file is reached.
* @exception IOException if an I/O error occurs.
*/
- public native int read() throws IOException;
+ public int read() throws IOException {
+ Object traceHandle = IoTrace.fileReadBegin(path);
+ int b = read0();
+ IoTrace.fileReadEnd(traceHandle, b == -1 ? -1 : 1);
+ return b;
+ }
+
+ private native int read0() throws IOException;
/**
* Reads a subarray as a sequence of bytes.
* @param b the data to be written
* @param off the start offset in the data
@@ -204,11 +217,14 @@
* <code>-1</code> if there is no more data because the end of
* the file has been reached.
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[]) throws IOException {
- return readBytes(b, 0, b.length);
+ Object traceHandle = IoTrace.fileReadBegin(path);
+ int bytesRead = readBytes(b, 0, b.length);
+ IoTrace.fileReadEnd(traceHandle, bytesRead);
+ return bytesRead;
}
/**
* Reads up to <code>len</code> bytes of data from this input stream
* into an array of bytes. If <code>len</code> is not zero, the method
@@ -226,11 +242,14 @@
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[], int off, int len) throws IOException {
- return readBytes(b, off, len);
+ Object traceHandle = IoTrace.fileReadBegin(path);
+ int bytesRead = readBytes(b, off, len);
+ IoTrace.fileReadEnd(traceHandle, bytesRead);
+ return bytesRead;
}
/**
* Skips over and discards <code>n</code> bytes of data from the
* input stream.
@@ -337,11 +356,11 @@
* @spec JSR-51
*/
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, true, false, this);
+ channel = FileChannelImpl.open(fd, path, true, false, this);
}
return channel;
}
}