Path: blob/master/src/java.base/unix/classes/sun/nio/ch/FileDispatcherImpl.java
67773 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.ch;2627import java.io.FileDescriptor;28import java.io.IOException;2930import jdk.internal.access.JavaIOFileDescriptorAccess;31import jdk.internal.access.SharedSecrets;3233class FileDispatcherImpl extends FileDispatcher {3435static {36IOUtil.load();37init();38}3940private static final JavaIOFileDescriptorAccess fdAccess =41SharedSecrets.getJavaIOFileDescriptorAccess();4243FileDispatcherImpl() {44}4546int read(FileDescriptor fd, long address, int len) throws IOException {47return read0(fd, address, len);48}4950int pread(FileDescriptor fd, long address, int len, long position)51throws IOException52{53return pread0(fd, address, len, position);54}5556long readv(FileDescriptor fd, long address, int len) throws IOException {57return readv0(fd, address, len);58}5960int write(FileDescriptor fd, long address, int len) throws IOException {61return write0(fd, address, len);62}6364int pwrite(FileDescriptor fd, long address, int len, long position)65throws IOException66{67return pwrite0(fd, address, len, position);68}6970long writev(FileDescriptor fd, long address, int len)71throws IOException72{73return writev0(fd, address, len);74}7576long seek(FileDescriptor fd, long offset) throws IOException {77return seek0(fd, offset);78}7980int force(FileDescriptor fd, boolean metaData) throws IOException {81return force0(fd, metaData);82}8384int truncate(FileDescriptor fd, long size) throws IOException {85return truncate0(fd, size);86}8788long size(FileDescriptor fd) throws IOException {89return size0(fd);90}9192int lock(FileDescriptor fd, boolean blocking, long pos, long size,93boolean shared) throws IOException94{95return lock0(fd, blocking, pos, size, shared);96}9798void release(FileDescriptor fd, long pos, long size) throws IOException {99release0(fd, pos, size);100}101102void close(FileDescriptor fd) throws IOException {103fdAccess.close(fd);104}105106void preClose(FileDescriptor fd) throws IOException {107preClose0(fd);108}109110void dup(FileDescriptor fd1, FileDescriptor fd2) throws IOException {111dup0(fd1, fd2);112}113114FileDescriptor duplicateForMapping(FileDescriptor fd) {115// file descriptor not required for mapping operations; okay116// to return invalid file descriptor.117return new FileDescriptor();118}119120boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {121return true;122}123124boolean transferToDirectlyNeedsPositionLock() {125return false;126}127128boolean canTransferToFromOverlappedMap() {129return canTransferToFromOverlappedMap0();130}131132int setDirectIO(FileDescriptor fd, String path) {133int result = -1;134try {135result = setDirect0(fd);136} catch (IOException e) {137throw new UnsupportedOperationException138("Error setting up DirectIO", e);139}140return result;141}142143// -- Native methods --144145static native int read0(FileDescriptor fd, long address, int len)146throws IOException;147148static native int pread0(FileDescriptor fd, long address, int len,149long position) throws IOException;150151static native long readv0(FileDescriptor fd, long address, int len)152throws IOException;153154static native int write0(FileDescriptor fd, long address, int len)155throws IOException;156157static native int pwrite0(FileDescriptor fd, long address, int len,158long position) throws IOException;159160static native long writev0(FileDescriptor fd, long address, int len)161throws IOException;162163static native int force0(FileDescriptor fd, boolean metaData)164throws IOException;165166static native long seek0(FileDescriptor fd, long offset)167throws IOException;168169static native int truncate0(FileDescriptor fd, long size)170throws IOException;171172static native long size0(FileDescriptor fd) throws IOException;173174static native int lock0(FileDescriptor fd, boolean blocking, long pos,175long size, boolean shared) throws IOException;176177static native void release0(FileDescriptor fd, long pos, long size)178throws IOException;179180// Shared with SocketDispatcher and DatagramDispatcher but181// NOT used by FileDispatcherImpl182static native void close0(FileDescriptor fd) throws IOException;183184static native void preClose0(FileDescriptor fd) throws IOException;185186static native void dup0(FileDescriptor fd1, FileDescriptor fd2) throws IOException;187188static native void closeIntFD(int fd) throws IOException;189190static native boolean canTransferToFromOverlappedMap0();191192static native int setDirect0(FileDescriptor fd) throws IOException;193194static native void init();195196}197198199