src/share/classes/java/io/RandomAccessFile.java
Print this page
*** 227,237 ****
}
if (name == null) {
throw new NullPointerException();
}
fd = new FileDescriptor();
! fd.incrementAndGetUseCount();
open(name, imode);
}
/**
* Returns the opaque file descriptor object associated with this
--- 227,237 ----
}
if (name == null) {
throw new NullPointerException();
}
fd = new FileDescriptor();
! fd.attach(this);
open(name, imode);
}
/**
* Returns the opaque file descriptor object associated with this
*** 240,250 ****
* @return the file descriptor object associated with this stream.
* @exception IOException if an I/O error occurs.
* @see java.io.FileDescriptor
*/
public final FileDescriptor getFD() throws IOException {
! if (fd != null) return fd;
throw new IOException();
}
/**
* Returns the unique {@link java.nio.channels.FileChannel FileChannel}
--- 240,252 ----
* @return the file descriptor object associated with this stream.
* @exception IOException if an I/O error occurs.
* @see java.io.FileDescriptor
*/
public final FileDescriptor getFD() throws IOException {
! if (fd != null) {
! return fd;
! }
throw new IOException();
}
/**
* Returns the unique {@link java.nio.channels.FileChannel FileChannel}
*** 266,286 ****
*/
public final FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
channel = FileChannelImpl.open(fd, true, rw, this);
-
- /*
- * FileDescriptor could be shared by FileInputStream or
- * FileOutputStream.
- * Ensure that FD is GC'ed only when all the streams/channels
- * are done using it.
- * Increment fd's use count. Invoking the channel's close()
- * method will result in decrementing the use count set for
- * the channel.
- */
- fd.incrementAndGetUseCount();
}
return channel;
}
}
--- 268,277 ----
*** 575,606 ****
return;
}
closed = true;
}
if (channel != null) {
- /*
- * Decrement FD use count associated with the channel. The FD use
- * count is incremented whenever a new channel is obtained from
- * this stream.
- */
- fd.decrementAndGetUseCount();
channel.close();
}
! /*
! * Decrement FD use count associated with this stream.
! * The count got incremented by FileDescriptor during its construction.
! */
! int useCount = fd.decrementAndGetUseCount();
!
! /*
! * If FileDescriptor is still in use by another stream, we
! * will not close it.
! */
! if (useCount <= 0) {
close0();
}
}
//
// Some "reading/writing Java data types" methods stolen from
// DataInputStream and DataOutputStream.
--- 566,583 ----
return;
}
closed = true;
}
if (channel != null) {
channel.close();
}
! fd.closeAll(new Closeable() {
! public void close() throws IOException {
close0();
}
+ });
}
//
// Some "reading/writing Java data types" methods stolen from
// DataInputStream and DataOutputStream.