@@ -19,13 +19,13 @@ impl DataInputStream {
19
19
interfaces : vec ! [ ] ,
20
20
methods : vec ! [
21
21
JavaMethodProto :: new( "<init>" , "(Ljava/io/InputStream;)V" , Self :: init, Default :: default ( ) ) ,
22
- JavaMethodProto :: new( "read" , "()I" , Self :: read_byte_int, Default :: default ( ) ) ,
23
- JavaMethodProto :: new( "read" , "([BII)I" , Self :: read, Default :: default ( ) ) ,
24
22
JavaMethodProto :: new( "readBoolean" , "()Z" , Self :: read_boolean, Default :: default ( ) ) ,
25
23
JavaMethodProto :: new( "readByte" , "()B" , Self :: read_byte, Default :: default ( ) ) ,
26
24
JavaMethodProto :: new( "readChar" , "()C" , Self :: read_char, Default :: default ( ) ) ,
27
25
JavaMethodProto :: new( "readDouble" , "()D" , Self :: read_double, Default :: default ( ) ) ,
28
26
JavaMethodProto :: new( "readFloat" , "()F" , Self :: read_float, Default :: default ( ) ) ,
27
+ JavaMethodProto :: new( "readFully" , "([B)V" , Self :: read_fully, Default :: default ( ) ) ,
28
+ JavaMethodProto :: new( "readFully" , "([BII)V" , Self :: read_fully_offset_length, Default :: default ( ) ) ,
29
29
JavaMethodProto :: new( "readInt" , "()I" , Self :: read_int, Default :: default ( ) ) ,
30
30
JavaMethodProto :: new( "readLong" , "()J" , Self :: read_long, Default :: default ( ) ) ,
31
31
JavaMethodProto :: new( "readShort" , "()S" , Self :: read_short, Default :: default ( ) ) ,
@@ -46,31 +46,6 @@ impl DataInputStream {
46
46
Ok ( ( ) )
47
47
}
48
48
49
- async fn read (
50
- jvm : & Jvm ,
51
- _: & mut RuntimeContext ,
52
- this : ClassInstanceRef < Self > ,
53
- b : ClassInstanceRef < Array < i8 > > ,
54
- off : i32 ,
55
- len : i32 ,
56
- ) -> Result < i32 > {
57
- tracing:: debug!( "java.io.DataInputStream::read({:?}, {:?}, {}, {})" , & this, & b, off, len) ;
58
-
59
- let r#in = jvm. get_field ( & this, "in" , "Ljava/io/InputStream;" ) . await ?;
60
- let result: i32 = jvm. invoke_virtual ( & r#in, "read" , "([BII)I" , ( b, off, len) ) . await ?;
61
-
62
- Ok ( result)
63
- }
64
-
65
- async fn read_byte_int ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i32 > {
66
- tracing:: debug!( "java.io.DataInputStream::read({:?})" , & this) ;
67
-
68
- let r#in = jvm. get_field ( & this, "in" , "Ljava/io/InputStream;" ) . await ?;
69
- let result: i32 = jvm. invoke_virtual ( & r#in, "read" , "()I" , ( ) ) . await ?;
70
-
71
- Ok ( result)
72
- }
73
-
74
49
async fn read_byte ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i8 > {
75
50
tracing:: debug!( "java.io.DataInputStream::readByte({:?})" , & this) ;
76
51
@@ -213,4 +188,36 @@ impl DataInputStream {
213
188
214
189
Ok ( JavaLangString :: from_rust_string ( jvm, & string) . await ?. into ( ) )
215
190
}
191
+
192
+ async fn read_fully ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , b : ClassInstanceRef < Array < i8 > > ) -> Result < ( ) > {
193
+ tracing:: debug!( "java.io.DataInputStream::readFully({:?}, {:?})" , & this, & b) ;
194
+
195
+ let length = jvm. array_length ( & b) . await ?;
196
+
197
+ let _: ( ) = jvm. invoke_virtual ( & this, "readFully" , "([BII)V" , ( b. clone ( ) , 0 , length as i32 ) ) . await ?;
198
+
199
+ Ok ( ( ) )
200
+ }
201
+
202
+ async fn read_fully_offset_length (
203
+ jvm : & Jvm ,
204
+ _: & mut RuntimeContext ,
205
+ this : ClassInstanceRef < Self > ,
206
+ b : ClassInstanceRef < Array < i8 > > ,
207
+ off : i32 ,
208
+ len : i32 ,
209
+ ) -> Result < ( ) > {
210
+ tracing:: debug!( "java.io.DataInputStream::readFully({:?}, {:?}, {}, {})" , & this, & b, off, len) ;
211
+
212
+ let mut read = 0 ;
213
+ while read < len {
214
+ let r: i32 = jvm. invoke_virtual ( & this, "read" , "([BII)I" , ( b. clone ( ) , off + read, len - read) ) . await ?;
215
+ if r == -1 {
216
+ return Err ( jvm. exception ( "java/io/EOFException" , "End of stream reached before reading fully" ) . await ) ;
217
+ }
218
+ read += r;
219
+ }
220
+
221
+ Ok ( ( ) )
222
+ }
216
223
}
0 commit comments