author | rriggs |
Fri, 09 Nov 2018 13:28:16 -0500 | |
changeset 52478 | b915bd68d907 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30784 | 2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
30784 | 26 |
#include <fcntl.h> |
27 |
#include <limits.h> |
|
28 |
||
2 | 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 |
|
26190
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
60 |
Java_java_io_FileInputStream_open0(JNIEnv *env, jobject this, jstring path) { |
2 | 61 |
fileOpen(env, this, path, fis_fd, O_RDONLY); |
62 |
} |
|
63 |
||
64 |
JNIEXPORT jint JNICALL |
|
22946
0a1379d15976
8033911: Simplify instrumentation of FileInputStream and RandomAccessFile
sla
parents:
17691
diff
changeset
|
65 |
Java_java_io_FileInputStream_read0(JNIEnv *env, jobject this) { |
2 | 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 |
|
41971
d94dec08aecc
8169556: Wrapping of FileInputStream's native skip and available methods
rriggs
parents:
30784
diff
changeset
|
76 |
Java_java_io_FileInputStream_skip0(JNIEnv *env, jobject this, jlong toSkip) { |
2 | 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; |
|
83 |
} |
|
84 |
if ((cur = IO_Lseek(fd, (jlong)0, (jint)SEEK_CUR)) == -1) { |
|
85 |
JNU_ThrowIOExceptionWithLastError(env, "Seek error"); |
|
86 |
} else if ((end = IO_Lseek(fd, toSkip, (jint)SEEK_CUR)) == -1) { |
|
87 |
JNU_ThrowIOExceptionWithLastError(env, "Seek error"); |
|
88 |
} |
|
89 |
return (end - cur); |
|
90 |
} |
|
91 |
||
92 |
JNIEXPORT jint JNICALL |
|
41971
d94dec08aecc
8169556: Wrapping of FileInputStream's native skip and available methods
rriggs
parents:
30784
diff
changeset
|
93 |
Java_java_io_FileInputStream_available0(JNIEnv *env, jobject this) { |
2 | 94 |
jlong ret; |
95 |
FD fd = GET_FD(this, fis_fd); |
|
96 |
if (fd == -1) { |
|
97 |
JNU_ThrowIOException (env, "Stream Closed"); |
|
98 |
return 0; |
|
99 |
} |
|
100 |
if (IO_Available(fd, &ret)) { |
|
101 |
if (ret > INT_MAX) { |
|
102 |
ret = (jlong) INT_MAX; |
|
17691
13931cd9405f
8011136: FileInputStream.available and skip inconsistencies
dxu
parents:
5506
diff
changeset
|
103 |
} else if (ret < 0) { |
13931cd9405f
8011136: FileInputStream.available and skip inconsistencies
dxu
parents:
5506
diff
changeset
|
104 |
ret = 0; |
2 | 105 |
} |
106 |
return jlong_to_jint(ret); |
|
107 |
} |
|
108 |
JNU_ThrowIOExceptionWithLastError(env, NULL); |
|
109 |
return 0; |
|
110 |
} |