@@ -19,13 +19,13 @@ impl DataInputStream {
1919 interfaces : vec ! [ ] ,
2020 methods : vec ! [
2121 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 ( ) ) ,
2422 JavaMethodProto :: new( "readBoolean" , "()Z" , Self :: read_boolean, Default :: default ( ) ) ,
2523 JavaMethodProto :: new( "readByte" , "()B" , Self :: read_byte, Default :: default ( ) ) ,
2624 JavaMethodProto :: new( "readChar" , "()C" , Self :: read_char, Default :: default ( ) ) ,
2725 JavaMethodProto :: new( "readDouble" , "()D" , Self :: read_double, Default :: default ( ) ) ,
2826 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 ( ) ) ,
2929 JavaMethodProto :: new( "readInt" , "()I" , Self :: read_int, Default :: default ( ) ) ,
3030 JavaMethodProto :: new( "readLong" , "()J" , Self :: read_long, Default :: default ( ) ) ,
3131 JavaMethodProto :: new( "readShort" , "()S" , Self :: read_short, Default :: default ( ) ) ,
@@ -46,31 +46,6 @@ impl DataInputStream {
4646 Ok ( ( ) )
4747 }
4848
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-
7449 async fn read_byte ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i8 > {
7550 tracing:: debug!( "java.io.DataInputStream::readByte({:?})" , & this) ;
7651
@@ -213,4 +188,36 @@ impl DataInputStream {
213188
214189 Ok ( JavaLangString :: from_rust_string ( jvm, & string) . await ?. into ( ) )
215190 }
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+ }
216223}
0 commit comments