Path: blob/master/src/java.base/unix/classes/sun/nio/ch/FileDispatcherImpl.java
41137 views
/*1* Copyright (c) 2000, 2019, 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}127128int setDirectIO(FileDescriptor fd, String path) {129int result = -1;130try {131result = setDirect0(fd);132} catch (IOException e) {133throw new UnsupportedOperationException134("Error setting up DirectIO", e);135}136return result;137}138139// -- Native methods --140141static native int read0(FileDescriptor fd, long address, int len)142throws IOException;143144static native int pread0(FileDescriptor fd, long address, int len,145long position) throws IOException;146147static native long readv0(FileDescriptor fd, long address, int len)148throws IOException;149150static native int write0(FileDescriptor fd, long address, int len)151throws IOException;152153static native int pwrite0(FileDescriptor fd, long address, int len,154long position) throws IOException;155156static native long writev0(FileDescriptor fd, long address, int len)157throws IOException;158159static native int force0(FileDescriptor fd, boolean metaData)160throws IOException;161162static native long seek0(FileDescriptor fd, long offset)163throws IOException;164165static native int truncate0(FileDescriptor fd, long size)166throws IOException;167168static native long size0(FileDescriptor fd) throws IOException;169170static native int lock0(FileDescriptor fd, boolean blocking, long pos,171long size, boolean shared) throws IOException;172173static native void release0(FileDescriptor fd, long pos, long size)174throws IOException;175176// Shared with SocketDispatcher and DatagramDispatcher but177// NOT used by FileDispatcherImpl178static native void close0(FileDescriptor fd) throws IOException;179180static native void preClose0(FileDescriptor fd) throws IOException;181182static native void dup0(FileDescriptor fd1, FileDescriptor fd2) throws IOException;183184static native void closeIntFD(int fd) throws IOException;185186static native int setDirect0(FileDescriptor fd) throws IOException;187188static native void init();189190}191192193