jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java
changeset 27263 819f5f87d485
parent 25859 3317bb8137f4
child 27937 0c9f63e42e91
--- a/jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java	Mon Oct 27 16:24:43 2014 -0700
+++ b/jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java	Tue Oct 28 15:36:27 2014 +0300
@@ -44,6 +44,8 @@
 import java.util.List;
 
 import sun.misc.Cleaner;
+import sun.misc.JavaIOFileDescriptorAccess;
+import sun.misc.SharedSecrets;
 import sun.security.action.GetPropertyAction;
 
 public class FileChannelImpl
@@ -52,6 +54,10 @@
     // Memory allocation size for mapping buffers
     private static final long allocationGranularity;
 
+    // Access to FileDispatcher internals
+    private static final JavaIOFileDescriptorAccess fdAccess =
+        SharedSecrets.getJavaIOFileDescriptorAccess();
+
     // Used to make native read and write calls
     private final FileDispatcher nd;
 
@@ -61,7 +67,6 @@
     // File access mode (immutable)
     private final boolean writable;
     private final boolean readable;
-    private final boolean append;
 
     // Required to prevent finalization of creating stream (immutable)
     private final Object parent;
@@ -77,31 +82,23 @@
     private final Object positionLock = new Object();
 
     private FileChannelImpl(FileDescriptor fd, String path, boolean readable,
-                            boolean writable, boolean append, Object parent)
+                            boolean writable, Object parent)
     {
         this.fd = fd;
         this.readable = readable;
         this.writable = writable;
-        this.append = append;
         this.parent = parent;
         this.path = path;
-        this.nd = new FileDispatcherImpl(append);
+        this.nd = new FileDispatcherImpl();
     }
 
-    // Used by FileInputStream.getChannel() and RandomAccessFile.getChannel()
+    // Used by FileInputStream.getChannel(), FileOutputStream.getChannel
+    // and RandomAccessFile.getChannel()
     public static FileChannel open(FileDescriptor fd, String path,
                                    boolean readable, boolean writable,
                                    Object parent)
     {
-        return new FileChannelImpl(fd, path, readable, writable, false, parent);
-    }
-
-    // Used by FileOutputStream.getChannel
-    public static FileChannel open(FileDescriptor fd, String path,
-                                   boolean readable, boolean writable,
-                                   boolean append, Object parent)
-    {
-        return new FileChannelImpl(fd, path, readable, writable, append, parent);
+        return new FileChannelImpl(fd, path, readable, writable, parent);
     }
 
     private void ensureOpen() throws IOException {
@@ -109,7 +106,6 @@
             throw new ClosedChannelException();
     }
 
-
     // -- Standard channel operations --
 
     protected void implCloseChannel() throws IOException {
@@ -258,6 +254,7 @@
                 ti = threads.add();
                 if (!isOpen())
                     return 0;
+                boolean append = fdAccess.getAppend(fd);
                 do {
                     // in append-mode then position is advanced to end before writing
                     p = (append) ? nd.size(fd) : position0(fd, -1);
@@ -284,7 +281,7 @@
                 if (!isOpen())
                     return null;
                 do {
-                    p  = position0(fd, newPosition);
+                    p = position0(fd, newPosition);
                 } while ((p == IOStatus.INTERRUPTED) && isOpen());
                 return this;
             } finally {