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 "jni.h"
27 #include "jni_util.h"
28 #include "jvm.h"
29
30 #include "io_util.h"
31 #include "io_util_md.h"
32 #include "java_io_FileOutputStream.h"
33
34 #include <fcntl.h>
35
36 /*******************************************************************/
37 /* BEGIN JNI ********* BEGIN JNI *********** BEGIN JNI ************/
38 /*******************************************************************/
39
40 jfieldID fos_fd; /* id for jobject 'fd' in java.io.FileOutputStream */
41
42 /**************************************************************
43 * static methods to store field ID's in initializers
44 */
45
46 JNIEXPORT void JNICALL
47 Java_java_io_FileOutputStream_initIDs(JNIEnv *env, jclass fdClass) {
48 fos_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;");
49 }
50
51 /**************************************************************
52 * Output stream
53 */
54
55 JNIEXPORT void JNICALL
56 Java_java_io_FileOutputStream_open0(JNIEnv *env, jobject this,
57 jstring path, jboolean append) {
58 fileOpen(env, this, path, fos_fd,
59 O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC));
60 }
61
62 JNIEXPORT void JNICALL
63 Java_java_io_FileOutputStream_write(JNIEnv *env, jobject this, jint byte, jboolean append) {
64 writeSingle(env, this, byte, append, fos_fd);
65 }
66
67 JNIEXPORT void JNICALL
68 Java_java_io_FileOutputStream_writeBytes(JNIEnv *env,
69 jobject this, jbyteArray bytes, jint off, jint len, jboolean append) {
70 writeBytes(env, this, bytes, off, len, append, fos_fd);
71 }
72
73 JNIEXPORT void JNICALL
74 Java_java_io_FileOutputStream_close0(JNIEnv *env, jobject this) {
75 fileClose(env, this, fos_fd);
76 }
|
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 "jni.h"
27 #include "jni_util.h"
28 #include "jvm.h"
29
30 #include "io_util.h"
31 #include "io_util_md.h"
32 #include "java_io_FileOutputStream.h"
33
34 #include <fcntl.h>
35
36 /*******************************************************************/
37 /* BEGIN JNI ********* BEGIN JNI *********** BEGIN JNI ************/
38 /*******************************************************************/
39
40 jfieldID fos_fd; /* id for jobject 'fd' in java.io.FileOutputStream */
41 jfieldID fos_pgsz; /* id for jobject 'pageSize' in java.io.FileOutputStream */
42
43 /**************************************************************
44 * static methods to store field ID's in initializers
45 */
46
47 JNIEXPORT void JNICALL
48 Java_java_io_FileOutputStream_initIDs(JNIEnv *env, jclass fdClass) {
49 fos_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;");
50 fos_pgsz = (*env)->GetFieldID(env, fdClass, "pageSize", "I");
51 }
52
53 /**************************************************************
54 * Output stream
55 */
56
57 JNIEXPORT void JNICALL
58 Java_java_io_FileOutputStream_open0(JNIEnv *env, jobject this,
59 jstring path, jboolean append, jboolean direct) {
60 if (direct) {
61 fileOpen(env, this, path, fos_fd,
62 O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC) | O_DIRECT);
63 } else {
64 fileOpen(env, this, path, fos_fd,
65 O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC));
66 }
67 }
68
69 JNIEXPORT void JNICALL
70 Java_java_io_FileOutputStream_write(JNIEnv *env, jobject this, jint byte, jboolean append) {
71 writeSingle(env, this, byte, append, fos_fd);
72 }
73
74 JNIEXPORT void JNICALL
75 Java_java_io_FileOutputStream_writeBytes(JNIEnv *env,
76 jobject this, jbyteArray bytes, jint off, jint len, jboolean append) {
77 writeBytes(env, this, bytes, off, len, append, fos_fd);
78 }
79
80 JNIEXPORT void JNICALL
81 Java_java_io_FileOutputStream_writeBytesD(JNIEnv *env,
82 jobject this, jbyteArray bytes, jint off, jint len, jboolean append) {
83 writeBytesD(env, this, bytes, off, len, append, fos_fd, fos_pgsz);
84 }
85
86 JNIEXPORT jint JNICALL
87 Java_java_io_FileOutputStream_getPageSize0(JNIEnv *env, jobject this) {
88 return getpagesize();
89 }
90
91 JNIEXPORT void JNICALL
92 Java_java_io_FileOutputStream_close0(JNIEnv *env, jobject this) {
93 fileClose(env, this, fos_fd);
94 }
95
96 JNIEXPORT jlong JNICALL
97 Java_java_io_FileOutputStream_getCurrentLocation0(JNIEnv *env, jobject this) {
98 FD fd;
99
100 fd = GET_FD(this, fos_fd);
101 if (fd == -1) {
102 JNU_ThrowIOException(env, "Stream Closed");
103 return -1;
104 }
105 jlong currentLocation = IO_Lseek(fd, 0, SEEK_CUR);
106 if (currentLocation == -1) {
107 JNU_ThrowIOExceptionWithLastError(env, "Seek failed");
108 }
109 return currentLocation;
110 }
111
|