47
48
49 JNIEXPORT void JNICALL
50 Java_java_io_RandomAccessFile_open(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 fileOpen(env, this, path, raf_fd, flags);
64 }
65
66 JNIEXPORT jint JNICALL
67 Java_java_io_RandomAccessFile_read(JNIEnv *env, jobject this) {
68 return readSingle(env, this, raf_fd);
69 }
70
71 JNIEXPORT jint JNICALL
72 Java_java_io_RandomAccessFile_readBytes(JNIEnv *env,
73 jobject this, jbyteArray bytes, jint off, jint len) {
74 return readBytes(env, this, bytes, off, len, raf_fd);
75 }
76
77 JNIEXPORT void JNICALL
78 Java_java_io_RandomAccessFile_write(JNIEnv *env, jobject this, jint byte) {
79 writeSingle(env, this, byte, JNI_FALSE, raf_fd);
80 }
81
82 JNIEXPORT void JNICALL
83 Java_java_io_RandomAccessFile_writeBytes(JNIEnv *env,
84 jobject this, jbyteArray bytes, jint off, jint len) {
85 writeBytes(env, this, bytes, off, len, JNI_FALSE, raf_fd);
86 }
87
88 JNIEXPORT jlong JNICALL
89 Java_java_io_RandomAccessFile_getFilePointer(JNIEnv *env, jobject this) {
90 FD fd;
91 jlong ret;
92
93 fd = GET_FD(this, raf_fd);
94 if (fd == -1) {
95 JNU_ThrowIOException(env, "Stream Closed");
96 return -1;
97 }
98 if ((ret = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
99 JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
100 }
101 return ret;
102 }
103
|
47
48
49 JNIEXPORT void JNICALL
50 Java_java_io_RandomAccessFile_open(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 fileOpen(env, this, path, raf_fd, flags);
64 }
65
66 JNIEXPORT jint JNICALL
67 Java_java_io_RandomAccessFile_read0(JNIEnv *env, jobject this) {
68 return readSingle(env, this, raf_fd);
69 }
70
71 JNIEXPORT jint JNICALL
72 Java_java_io_RandomAccessFile_readBytes0(JNIEnv *env,
73 jobject this, jbyteArray bytes, jint off, jint len) {
74 return readBytes(env, this, bytes, off, len, raf_fd);
75 }
76
77 JNIEXPORT void JNICALL
78 Java_java_io_RandomAccessFile_write0(JNIEnv *env, jobject this, jint byte) {
79 writeSingle(env, this, byte, JNI_FALSE, raf_fd);
80 }
81
82 JNIEXPORT void JNICALL
83 Java_java_io_RandomAccessFile_writeBytes0(JNIEnv *env,
84 jobject this, jbyteArray bytes, jint off, jint len) {
85 writeBytes(env, this, bytes, off, len, JNI_FALSE, raf_fd);
86 }
87
88 JNIEXPORT jlong JNICALL
89 Java_java_io_RandomAccessFile_getFilePointer(JNIEnv *env, jobject this) {
90 FD fd;
91 jlong ret;
92
93 fd = GET_FD(this, raf_fd);
94 if (fd == -1) {
95 JNU_ThrowIOException(env, "Stream Closed");
96 return -1;
97 }
98 if ((ret = IO_Lseek(fd, 0L, SEEK_CUR)) == -1) {
99 JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
100 }
101 return ret;
102 }
103
|