001: /*
002: * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.nio.ch;
027:
028: import java.io.*;
029:
030: /**
031: * Allows different platforms to call different native methods
032: * for read and write operations.
033: */
034:
035: class FileDispatcher extends NativeDispatcher {
036:
037: static {
038: Util.load();
039: }
040:
041: int read(FileDescriptor fd, long address, int len)
042: throws IOException {
043: return read0(fd, address, len);
044: }
045:
046: int pread(FileDescriptor fd, long address, int len, long position,
047: Object lock) throws IOException {
048: synchronized (lock) {
049: return pread0(fd, address, len, position);
050: }
051: }
052:
053: long readv(FileDescriptor fd, long address, int len)
054: throws IOException {
055: return readv0(fd, address, len);
056: }
057:
058: int write(FileDescriptor fd, long address, int len)
059: throws IOException {
060: return write0(fd, address, len);
061: }
062:
063: int pwrite(FileDescriptor fd, long address, int len, long position,
064: Object lock) throws IOException {
065: synchronized (lock) {
066: return pwrite0(fd, address, len, position);
067: }
068: }
069:
070: long writev(FileDescriptor fd, long address, int len)
071: throws IOException {
072: return writev0(fd, address, len);
073: }
074:
075: void close(FileDescriptor fd) throws IOException {
076: close0(fd);
077: }
078:
079: //-- Native methods
080:
081: static native int read0(FileDescriptor fd, long address, int len)
082: throws IOException;
083:
084: static native int pread0(FileDescriptor fd, long address, int len,
085: long position) throws IOException;
086:
087: static native long readv0(FileDescriptor fd, long address, int len)
088: throws IOException;
089:
090: static native int write0(FileDescriptor fd, long address, int len)
091: throws IOException;
092:
093: static native int pwrite0(FileDescriptor fd, long address, int len,
094: long position) throws IOException;
095:
096: static native long writev0(FileDescriptor fd, long address, int len)
097: throws IOException;
098:
099: static native void close0(FileDescriptor fd) throws IOException;
100:
101: static native void closeByHandle(long fd) throws IOException;
102:
103: }
|