< prev index next >

src/java.base/share/native/libjava/FileInputStream.c

Print this page




  25 
  26 #include <fcntl.h>
  27 #include <limits.h>
  28 
  29 #include "jni.h"
  30 #include "jni_util.h"
  31 #include "jlong.h"
  32 #include "io_util.h"
  33 
  34 #include "jvm.h"
  35 
  36 #include "java_io_FileInputStream.h"
  37 
  38 #include "io_util_md.h"
  39 
  40 /*******************************************************************/
  41 /*  BEGIN JNI ********* BEGIN JNI *********** BEGIN JNI ************/
  42 /*******************************************************************/
  43 
  44 jfieldID fis_fd; /* id for jobject 'fd' in java.io.FileInputStream */

  45 
  46 /**************************************************************
  47  * static methods to store field ID's in initializers
  48  */
  49 
  50 JNIEXPORT void JNICALL
  51 Java_java_io_FileInputStream_initIDs(JNIEnv *env, jclass fdClass) {
  52     fis_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;");

  53 }
  54 
  55 /**************************************************************
  56  * Input stream
  57  */
  58 
  59 JNIEXPORT void JNICALL
  60 Java_java_io_FileInputStream_open0(JNIEnv *env, jobject this, jstring path) {
  61     fileOpen(env, this, path, fis_fd, O_RDONLY);
  62 }
  63 
  64 JNIEXPORT jint JNICALL
  65 Java_java_io_FileInputStream_read0(JNIEnv *env, jobject this) {
  66     return readSingle(env, this, fis_fd);
  67 }
  68 
  69 JNIEXPORT jint JNICALL
  70 Java_java_io_FileInputStream_readBytes(JNIEnv *env, jobject this,
  71         jbyteArray bytes, jint off, jint len) {
  72     return readBytes(env, this, bytes, off, len, fis_fd);
  73 }
  74 
  75 JNIEXPORT jlong JNICALL
  76 Java_java_io_FileInputStream_skip(JNIEnv *env, jobject this, jlong toSkip) {
  77     jlong cur = jlong_zero;
  78     jlong end = jlong_zero;
  79     FD fd = GET_FD(this, fis_fd);
  80     if (fd == -1) {
  81         JNU_ThrowIOException (env, "Stream Closed");
  82         return 0;




  25 
  26 #include <fcntl.h>
  27 #include <limits.h>
  28 
  29 #include "jni.h"
  30 #include "jni_util.h"
  31 #include "jlong.h"
  32 #include "io_util.h"
  33 
  34 #include "jvm.h"
  35 
  36 #include "java_io_FileInputStream.h"
  37 
  38 #include "io_util_md.h"
  39 
  40 /*******************************************************************/
  41 /*  BEGIN JNI ********* BEGIN JNI *********** BEGIN JNI ************/
  42 /*******************************************************************/
  43 
  44 jfieldID fis_fd; /* id for jobject 'fd' in java.io.FileInputStream */
  45 jfieldID fis_pgsz; /* id for jobject 'pageSize' in java.io.FileInputStream */
  46 
  47 /**************************************************************
  48  * static methods to store field ID's in initializers
  49  */
  50 
  51 JNIEXPORT void JNICALL
  52 Java_java_io_FileInputStream_initIDs(JNIEnv *env, jclass fdClass) {
  53     fis_fd = (*env)->GetFieldID(env, fdClass, "fd", "Ljava/io/FileDescriptor;");
  54     fis_pgsz = (*env)->GetFieldID(env, fdClass, "pageSize", "I");
  55 }
  56 
  57 /**************************************************************
  58  * Input stream
  59  */





  60 
  61 JNIEXPORT jint JNICALL
  62 Java_java_io_FileInputStream_read0(JNIEnv *env, jobject this) {
  63     return readSingle(env, this, fis_fd);
  64 }
  65 
  66 JNIEXPORT jint JNICALL
  67 Java_java_io_FileInputStream_readBytes(JNIEnv *env, jobject this,
  68         jbyteArray bytes, jint off, jint len) {
  69     return readBytes(env, this, bytes, off, len, fis_fd);
  70 }
  71 
  72 JNIEXPORT jlong JNICALL
  73 Java_java_io_FileInputStream_skip(JNIEnv *env, jobject this, jlong toSkip) {
  74     jlong cur = jlong_zero;
  75     jlong end = jlong_zero;
  76     FD fd = GET_FD(this, fis_fd);
  77     if (fd == -1) {
  78         JNU_ThrowIOException (env, "Stream Closed");
  79         return 0;


< prev index next >