22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "jni.h" 27 #include "jni_util.h" 28 #include "jlong.h" 29 #include "jvm.h" 30 31 #include "io_util.h" 32 #include "io_util_md.h" 33 #include "java_io_RandomAccessFile.h" 34 35 #include <fcntl.h> 36 37 /* 38 * static method to store field ID's in initializers 39 */ 40 41 jfieldID raf_fd; /* id for jobject 'fd' in java.io.RandomAccessFile */ 42 43 JNIEXPORT void JNICALL 44 Java_java_io_RandomAccessFile_initIDs(JNIEnv *env, jclass fdClass) { 45 raf_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;"); 46 } 47 48 49 JNIEXPORT void JNICALL 50 Java_java_io_RandomAccessFile_open0(JNIEnv *env, 51 jobject this, jstring path, jint mode) 52 { 53 int flags = 0; 54 if (mode & java_io_RandomAccessFile_O_RDONLY) 55 flags = O_RDONLY; 56 else if (mode & java_io_RandomAccessFile_O_RDWR) { 57 flags = O_RDWR | O_CREAT; 58 if (mode & java_io_RandomAccessFile_O_SYNC) 59 flags |= O_SYNC; 60 else if (mode & java_io_RandomAccessFile_O_DSYNC) 61 flags |= O_DSYNC; 62 } 63 #ifdef WIN32 64 if (mode & java_io_RandomAccessFile_O_TEMPORARY) 65 flags |= O_TEMPORARY; 66 #endif 67 fileOpen(env, this, path, raf_fd, flags); 68 } 69 70 JNIEXPORT jint JNICALL 71 Java_java_io_RandomAccessFile_read0(JNIEnv *env, jobject this) { 72 return readSingle(env, this, raf_fd); 73 } 74 75 JNIEXPORT jint JNICALL 76 Java_java_io_RandomAccessFile_readBytes(JNIEnv *env, 77 jobject this, jbyteArray bytes, jint off, jint len) { 78 return readBytes(env, this, bytes, off, len, raf_fd); 79 } 80 81 JNIEXPORT void JNICALL 82 Java_java_io_RandomAccessFile_write0(JNIEnv *env, jobject this, jint byte) { 83 writeSingle(env, this, byte, JNI_FALSE, raf_fd); 84 } 85 86 JNIEXPORT void JNICALL 87 Java_java_io_RandomAccessFile_writeBytes(JNIEnv *env, | 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "jni.h" 27 #include "jni_util.h" 28 #include "jlong.h" 29 #include "jvm.h" 30 31 #include "io_util.h" 32 #include "io_util_md.h" 33 #include "java_io_RandomAccessFile.h" 34 35 #include <fcntl.h> 36 37 /* 38 * static method to store field ID's in initializers 39 */ 40 41 jfieldID raf_fd; /* id for jobject 'fd' in java.io.RandomAccessFile */ 42 jfieldID raf_pgsz; /* id for jobject 'pageSize' in java.io.RandomAccessFile */ 43 44 JNIEXPORT void JNICALL 45 Java_java_io_RandomAccessFile_initIDs(JNIEnv *env, jclass fdClass) { 46 raf_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;"); 47 raf_pgsz = (*env)->GetFieldID(env, fdClass, "pageSize", "I"); 48 } 49 50 JNIEXPORT jint JNICALL 51 Java_java_io_RandomAccessFile_read0(JNIEnv *env, jobject this) { 52 return readSingle(env, this, raf_fd); 53 } 54 55 JNIEXPORT jint JNICALL 56 Java_java_io_RandomAccessFile_readBytes(JNIEnv *env, 57 jobject this, jbyteArray bytes, jint off, jint len) { 58 return readBytes(env, this, bytes, off, len, raf_fd); 59 } 60 61 JNIEXPORT void JNICALL 62 Java_java_io_RandomAccessFile_write0(JNIEnv *env, jobject this, jint byte) { 63 writeSingle(env, this, byte, JNI_FALSE, raf_fd); 64 } 65 66 JNIEXPORT void JNICALL 67 Java_java_io_RandomAccessFile_writeBytes(JNIEnv *env, |