< prev index next >

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

Print this page




 184                 break;
 185             }
 186             if (append == JNI_TRUE) {
 187                 n = IO_Append(fd, buf+off, len);
 188             } else {
 189                 n = IO_Write(fd, buf+off, len);
 190             }
 191             if (n == -1) {
 192                 JNU_ThrowIOExceptionWithLastError(env, "Write error");
 193                 break;
 194             }
 195             off += n;
 196             len -= n;
 197         }
 198     }
 199     if (buf != stackBuf) {
 200         free(buf);
 201     }
 202 }
 203 
 204 JNIEXPORT void JNICALL
 205 throwFileNotFoundException(JNIEnv *env, jstring path)
 206 {
 207     char buf[256];
 208     size_t n;
 209     jobject x;
 210     jstring why = NULL;
 211 
 212     n = getLastErrorString(buf, sizeof(buf));
 213     if (n > 0) {
 214         why = JNU_NewStringPlatform(env, buf);
 215         CHECK_NULL(why);
 216     }
 217     x = JNU_NewObjectByName(env,
 218                             "java/io/FileNotFoundException",
 219                             "(Ljava/lang/String;Ljava/lang/String;)V",
 220                             path, why);
 221     if (x != NULL) {
 222         (*env)->Throw(env, x);
 223     }
 224 }


 184                 break;
 185             }
 186             if (append == JNI_TRUE) {
 187                 n = IO_Append(fd, buf+off, len);
 188             } else {
 189                 n = IO_Write(fd, buf+off, len);
 190             }
 191             if (n == -1) {
 192                 JNU_ThrowIOExceptionWithLastError(env, "Write error");
 193                 break;
 194             }
 195             off += n;
 196             len -= n;
 197         }
 198     }
 199     if (buf != stackBuf) {
 200         free(buf);
 201     }
 202 }
 203 
 204 void
 205 throwFileNotFoundException(JNIEnv *env, jstring path)
 206 {
 207     char buf[256];
 208     size_t n;
 209     jobject x;
 210     jstring why = NULL;
 211 
 212     n = getLastErrorString(buf, sizeof(buf));
 213     if (n > 0) {
 214         why = JNU_NewStringPlatform(env, buf);
 215         CHECK_NULL(why);
 216     }
 217     x = JNU_NewObjectByName(env,
 218                             "java/io/FileNotFoundException",
 219                             "(Ljava/lang/String;Ljava/lang/String;)V",
 220                             path, why);
 221     if (x != NULL) {
 222         (*env)->Throw(env, x);
 223     }
 224 }
< prev index next >