@@ -16,6 +16,7 @@ impl ByteArrayInputStream {
1616 interfaces : vec ! [ ] ,
1717 methods : vec ! [
1818 JavaMethodProto :: new( "<init>" , "([B)V" , Self :: init, Default :: default ( ) ) ,
19+ JavaMethodProto :: new( "<init>" , "([BII)V" , Self :: init_with_offset_length, Default :: default ( ) ) ,
1920 JavaMethodProto :: new( "available" , "()I" , Self :: available, Default :: default ( ) ) ,
2021 JavaMethodProto :: new( "read" , "([BII)I" , Self :: read, Default :: default ( ) ) ,
2122 JavaMethodProto :: new( "read" , "()I" , Self :: read_byte, Default :: default ( ) ) ,
@@ -26,27 +27,49 @@ impl ByteArrayInputStream {
2627 fields : vec ! [
2728 JavaFieldProto :: new( "buf" , "[B" , Default :: default ( ) ) ,
2829 JavaFieldProto :: new( "pos" , "I" , Default :: default ( ) ) ,
30+ JavaFieldProto :: new( "count" , "I" , Default :: default ( ) ) ,
2931 ] ,
3032 }
3133 }
3234
33- async fn init ( jvm : & Jvm , _: & mut RuntimeContext , mut this : ClassInstanceRef < Self > , data : ClassInstanceRef < Array < i8 > > ) -> Result < ( ) > {
34- tracing:: debug!( "java.io.ByteArrayInputStream::<init>({:?}, {:?})" , & this, & data) ;
35+ async fn init ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , data : ClassInstanceRef < Array < i8 > > ) -> Result < ( ) > {
36+ tracing:: debug!( "java.io.ByteArrayInputStream::<init>({this:?}, {data:?})" ) ;
37+
38+ let count = jvm. array_length ( & data) . await ?;
39+
40+ let _: ( ) = jvm
41+ . invoke_special ( & this, "java/io/ByteArrayInputStream" , "<init>" , "([BII)V" , ( data, 0 , count as i32 ) )
42+ . await ?;
43+
44+ Ok ( ( ) )
45+ }
46+
47+ async fn init_with_offset_length (
48+ jvm : & Jvm ,
49+ _: & mut RuntimeContext ,
50+ mut this : ClassInstanceRef < Self > ,
51+ data : ClassInstanceRef < Array < i8 > > ,
52+ offset : i32 ,
53+ length : i32 ,
54+ ) -> Result < ( ) > {
55+ tracing:: debug!( "java.io.ByteArrayInputStream::<init>({this:?}, {data:?}, {offset}, {length})" ) ;
56+
57+ let _: ( ) = jvm. invoke_special ( & this, "java/io/InputStream" , "<init>" , "()V" , ( ) ) . await ?;
3558
3659 jvm. put_field ( & mut this, "buf" , "[B" , data) . await ?;
37- jvm. put_field ( & mut this, "pos" , "I" , 0 ) . await ?;
60+ jvm. put_field ( & mut this, "pos" , "I" , offset) . await ?;
61+ jvm. put_field ( & mut this, "count" , "I" , length) . await ?;
3862
3963 Ok ( ( ) )
4064 }
4165
4266 async fn available ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i32 > {
4367 tracing:: debug!( "java.io.ByteArrayInputStream::available({:?})" , & this) ;
4468
45- let buf = jvm. get_field ( & this, "buf " , "[B " ) . await ?;
69+ let count : i32 = jvm. get_field ( & this, "count " , "I " ) . await ?;
4670 let pos: i32 = jvm. get_field ( & this, "pos" , "I" ) . await ?;
47- let buf_length = jvm. array_length ( & buf) . await ? as i32 ;
4871
49- Ok ( ( buf_length - pos) as _ )
72+ Ok ( ( count - pos) as _ )
5073 }
5174
5275 async fn read (
0 commit comments