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 #include <sys/types.h> 27 #include <sys/stat.h> 28 #include <fcntl.h> 29 #include <unistd.h> 30 31 #include "jni.h" 32 #include "jni_util.h" 33 #include "jvm.h" 34 #include "io_util.h" 35 #include "io_util_md.h" 36 37 #include "java_io_RandomAccessFile.h" 38 39 extern jfieldID raf_fd; /* id for jobject 'fd' in java.io.RandomAccessFile */ 40 41 /********************************************************************* 42 * Platform specific implementation of input stream native methods 43 */ 44 45 JNIEXPORT void JNICALL 46 Java_java_io_RandomAccessFile_close0(JNIEnv *env, jobject this) { 47 fileClose(env, this, raf_fd); 48 } | 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 #include <sys/types.h> 27 #include <sys/stat.h> 28 #include <fcntl.h> 29 #include <unistd.h> 30 31 #include "jni.h" 32 #include "jni_util.h" 33 #include "jvm.h" 34 #include "io_util.h" 35 #include "io_util_md.h" 36 37 #include "java_io_RandomAccessFile.h" 38 39 extern jfieldID raf_fd; /* id for jobject 'fd' in java.io.RandomAccessFile */ 40 extern jfieldID raf_pgsz; /* id for jobject 'fd' in java.io.RandomAccessFile */ 41 42 /********************************************************************* 43 * Platform specific implementation of input stream native methods 44 */ 45 46 JNIEXPORT void JNICALL 47 Java_java_io_RandomAccessFile_close0(JNIEnv *env, jobject this) { 48 fileClose(env, this, raf_fd); 49 } 50 51 JNIEXPORT void JNICALL 52 Java_java_io_RandomAccessFile_open0(JNIEnv *env, 53 jobject this, jstring path, jint mode) 54 { 55 int flags = 0; 56 if (mode & java_io_RandomAccessFile_O_RDONLY) { 57 flags = O_RDONLY; 58 if (mode & java_io_RandomAccessFile_O_DIRECT) 59 flags |= O_DIRECT; 60 } 61 else if (mode & java_io_RandomAccessFile_O_RDWR) { 62 flags = O_RDWR | O_CREAT; 63 if (mode & java_io_RandomAccessFile_O_SYNC) 64 flags |= O_SYNC; 65 else if (mode & java_io_RandomAccessFile_O_DSYNC) 66 flags |= O_DSYNC; 67 else if (mode & java_io_RandomAccessFile_O_DIRECT) 68 flags |= O_DIRECT; 69 } 70 fileOpen(env, this, path, raf_fd, flags); 71 } 72 73 JNIEXPORT jlong JNICALL 74 Java_java_io_RandomAccessFile_getCurrentLocation0(JNIEnv *env, jobject this) { 75 76 FD fd; 77 78 fd = GET_FD(this, raf_fd); 79 if (fd == -1) { 80 JNU_ThrowIOException(env, "Stream Closed"); 81 return -1; 82 } 83 jlong currentLocation = IO_Lseek(fd, 0, SEEK_CUR); 84 if (currentLocation == -1) { 85 JNU_ThrowIOExceptionWithLastError(env, "Seek failed"); 86 } 87 return currentLocation; 88 } 89 90 JNIEXPORT jint JNICALL 91 Java_java_io_RandomAccessFile_getPageSize0(JNIEnv *env, jobject this) { 92 return getpagesize(); 93 } 94 95 JNIEXPORT jint JNICALL 96 Java_java_io_RandomAccessFile_readBytesD(JNIEnv *env, 97 jobject this, jbyteArray bytes, jint off, jint len) { 98 return readBytesD(env, this, bytes, off, len, raf_fd, raf_pgsz); 99 } 100 101 JNIEXPORT void JNICALL 102 Java_java_io_RandomAccessFile_writeBytesD(JNIEnv *env, 103 jobject this, jbyteArray bytes, jint off, jint len) { 104 writeBytesD(env, this, bytes, off, len, JNI_FALSE, raf_fd, raf_pgsz); 105 } |