< prev index next >

src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.nio.ch;
  27 
  28 import java.io.FileDescriptor;
  29 import java.io.IOException;
  30 import java.security.PrivilegedAction;
  31 import jdk.internal.misc.SharedSecrets;
  32 import jdk.internal.misc.JavaIOFileDescriptorAccess;

  33 
  34 class FileDispatcherImpl extends FileDispatcher {
  35 
  36     private static final JavaIOFileDescriptorAccess fdAccess =
  37         SharedSecrets.getJavaIOFileDescriptorAccess();
  38 
  39     // set to true if fast file transmission (TransmitFile) is enabled
  40     private static final boolean fastFileTransfer;
  41 
  42     FileDispatcherImpl() { }
  43 
  44     @Override
  45     boolean needsPositionLock() {
  46         return true;
  47     }
  48 
  49     int read(FileDescriptor fd, long address, int len)
  50         throws IOException
  51     {
  52         return read0(fd, address, len);


 102         close0(fd);
 103     }
 104 
 105     FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException {
 106         // on Windows we need to keep a handle to the file
 107         FileDescriptor result = new FileDescriptor();
 108         long handle = duplicateHandle(fdAccess.getHandle(fd));
 109         fdAccess.setHandle(result, handle);
 110         return result;
 111     }
 112 
 113     boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
 114         return fastFileTransfer && sc.isBlocking();
 115     }
 116 
 117     boolean transferToDirectlyNeedsPositionLock() {
 118         return true;
 119     }
 120 
 121     static boolean isFastFileTransferRequested() {
 122         String fileTransferProp = java.security.AccessController.doPrivileged(
 123             new PrivilegedAction<String>() {
 124                 @Override
 125                 public String run() {
 126                     return System.getProperty("jdk.nio.enableFastFileTransfer");
 127                 }
 128             });
 129         boolean enable;
 130         if ("".equals(fileTransferProp)) {
 131             enable = true;
 132         } else {
 133             enable = Boolean.parseBoolean(fileTransferProp);
 134         }
 135         return enable;
 136     }
 137 
 138     static {
 139         IOUtil.load();
 140         fastFileTransfer = isFastFileTransferRequested();
 141     }
 142 
 143     //-- Native methods
 144 
 145     static native int read0(FileDescriptor fd, long address, int len)
 146         throws IOException;
 147 
 148     static native int pread0(FileDescriptor fd, long address, int len,




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.nio.ch;
  27 
  28 import java.io.FileDescriptor;
  29 import java.io.IOException;

  30 import jdk.internal.misc.SharedSecrets;
  31 import jdk.internal.misc.JavaIOFileDescriptorAccess;
  32 import sun.security.action.GetPropertyAction;
  33 
  34 class FileDispatcherImpl extends FileDispatcher {
  35 
  36     private static final JavaIOFileDescriptorAccess fdAccess =
  37         SharedSecrets.getJavaIOFileDescriptorAccess();
  38 
  39     // set to true if fast file transmission (TransmitFile) is enabled
  40     private static final boolean fastFileTransfer;
  41 
  42     FileDispatcherImpl() { }
  43 
  44     @Override
  45     boolean needsPositionLock() {
  46         return true;
  47     }
  48 
  49     int read(FileDescriptor fd, long address, int len)
  50         throws IOException
  51     {
  52         return read0(fd, address, len);


 102         close0(fd);
 103     }
 104 
 105     FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException {
 106         // on Windows we need to keep a handle to the file
 107         FileDescriptor result = new FileDescriptor();
 108         long handle = duplicateHandle(fdAccess.getHandle(fd));
 109         fdAccess.setHandle(result, handle);
 110         return result;
 111     }
 112 
 113     boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
 114         return fastFileTransfer && sc.isBlocking();
 115     }
 116 
 117     boolean transferToDirectlyNeedsPositionLock() {
 118         return true;
 119     }
 120 
 121     static boolean isFastFileTransferRequested() {
 122         String fileTransferProp = GetPropertyAction
 123                 .getProperty("jdk.nio.enableFastFileTransfer");





 124         boolean enable;
 125         if ("".equals(fileTransferProp)) {
 126             enable = true;
 127         } else {
 128             enable = Boolean.parseBoolean(fileTransferProp);
 129         }
 130         return enable;
 131     }
 132 
 133     static {
 134         IOUtil.load();
 135         fastFileTransfer = isFastFileTransferRequested();
 136     }
 137 
 138     //-- Native methods
 139 
 140     static native int read0(FileDescriptor fd, long address, int len)
 141         throws IOException;
 142 
 143     static native int pread0(FileDescriptor fd, long address, int len,


< prev index next >