src/share/classes/java/io/FileInputStream.java
Print this page
rev 5501 : imported patch io-trace
*** 25,34 ****
--- 25,35 ----
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,58 ****
--- 50,62 ----
class FileInputStream extends InputStream
{
/* File Descriptor - handle to the open file */
private final FileDescriptor fd;
+ /* The path of the referenced file (null if the stream is created with a file descriptor) */
+ private final String path;
+
private FileChannel channel = null;
private final Object closeLock = new Object();
private volatile boolean closed = false;
*** 133,142 ****
--- 137,147 ----
if (name == null) {
throw new NullPointerException();
}
fd = new FileDescriptor();
fd.incrementAndGetUseCount();
+ this.path = name;
open(name);
}
/**
* Creates a <code>FileInputStream</code> by using the file descriptor
*** 169,178 ****
--- 174,184 ----
}
if (security != null) {
security.checkRead(fdObj);
}
fd = fdObj;
+ path = null;
/*
* FileDescriptor is being shared by streams.
* Ensure that it's GC'ed only when all the streams/channels are done
* using it.
*** 192,202 ****
*
* @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;
/**
* Reads a subarray as a sequence of bytes.
* @param b the data to be written
* @param off the start offset in the data
--- 198,219 ----
*
* @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 int read() throws IOException {
! Object traceContext = IoTrace.fileReadBegin(path);
! int b = 0;
! try {
! b = read0();
! } finally {
! IoTrace.fileReadEnd(traceContext, b == -1 ? 0 : 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
*** 215,225 ****
* <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);
}
/**
* 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
--- 232,249 ----
* <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 {
! Object traceContext = IoTrace.fileReadBegin(path);
! int bytesRead = 0;
! try {
! bytesRead = readBytes(b, 0, b.length);
! } finally {
! IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : 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
*** 237,247 ****
* <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);
}
/**
* Skips over and discards <code>n</code> bytes of data from the
* input stream.
--- 261,278 ----
* <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 {
! Object traceContext = IoTrace.fileReadBegin(path);
! int bytesRead = 0;
! try {
! bytesRead = readBytes(b, off, len);
! } finally {
! IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
! }
! return bytesRead;
}
/**
* Skips over and discards <code>n</code> bytes of data from the
* input stream.
*** 359,369 ****
* @spec JSR-51
*/
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
! channel = FileChannelImpl.open(fd, true, false, this);
/*
* Increment fd's use count. Invoking the channel's close()
* method will result in decrementing the use count set for
* the channel.
--- 390,400 ----
* @spec JSR-51
*/
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
! channel = FileChannelImpl.open(fd, path, true, false, this);
/*
* Increment fd's use count. Invoking the channel's close()
* method will result in decrementing the use count set for
* the channel.