@@ -21,8 +21,10 @@ impl DataOutputStream {
2121 JavaMethodProto :: new( "write" , "(I)V" , Self :: write, Default :: default ( ) ) ,
2222 JavaMethodProto :: new( "writeByte" , "(I)V" , Self :: write, Default :: default ( ) ) ,
2323 JavaMethodProto :: new( "writeInt" , "(I)V" , Self :: write_int, Default :: default ( ) ) ,
24+ JavaMethodProto :: new( "writeShort" , "(I)V" , Self :: write_short, Default :: default ( ) ) ,
2425 JavaMethodProto :: new( "writeLong" , "(J)V" , Self :: write_long, Default :: default ( ) ) ,
2526 JavaMethodProto :: new( "writeChars" , "(Ljava/lang/String;)V" , Self :: write_chars, Default :: default ( ) ) ,
27+ JavaMethodProto :: new( "writeUTF" , "(Ljava/lang/String;)V" , Self :: write_utf, Default :: default ( ) ) ,
2628 JavaMethodProto :: new( "close" , "()V" , Self :: close, Default :: default ( ) ) ,
2729 JavaMethodProto :: new( "flush" , "()V" , Self :: flush, Default :: default ( ) ) ,
2830 ] ,
@@ -49,6 +51,19 @@ impl DataOutputStream {
4951 Ok ( ( ) )
5052 }
5153
54+ async fn write_short ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , s : i32 ) -> Result < ( ) > {
55+ tracing:: debug!( "java.io.DataOutputStream::writeShort({:?}, {:?})" , & this, s) ;
56+
57+ let bytes = ( s as i16 ) . to_be_bytes ( ) ;
58+ let mut byte_array = jvm. instantiate_array ( "B" , bytes. len ( ) as _ ) . await ?;
59+ jvm. store_array ( & mut byte_array, 0 , cast_vec :: < u8 , i8 > ( bytes. to_vec ( ) ) ) . await ?;
60+
61+ let out = jvm. get_field ( & this, "out" , "Ljava/io/OutputStream;" ) . await ?;
62+ let _: ( ) = jvm. invoke_virtual ( & out, "write" , "([B)V" , ( byte_array, ) ) . await ?;
63+
64+ Ok ( ( ) )
65+ }
66+
5267 async fn write_int ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , i : i32 ) -> Result < ( ) > {
5368 tracing:: debug!( "java.io.DataOutputStream::writeInt({:?}, {:?})" , & this, i) ;
5469
@@ -86,6 +101,21 @@ impl DataOutputStream {
86101 Ok ( ( ) )
87102 }
88103
104+ async fn write_utf ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , s : ClassInstanceRef < JavaChar > ) -> Result < ( ) > {
105+ tracing:: debug!( "java.io.DataOutputStream::writeUTF({:?}, {:?})" , & this, & s) ;
106+
107+ // TODO handle modified utf-8
108+ let bytes: ClassInstanceRef < Array < i8 > > = jvm. invoke_virtual ( & s, "getBytes" , "()[B" , ( ) ) . await ?;
109+ let length = jvm. array_length ( & bytes) . await ?;
110+
111+ let _: ( ) = jvm. invoke_virtual ( & this, "writeShort" , "(I)V" , ( length as i32 , ) ) . await ?;
112+
113+ let out = jvm. get_field ( & this, "out" , "Ljava/io/OutputStream;" ) . await ?;
114+ let _: ( ) = jvm. invoke_virtual ( & out, "write" , "([B)V" , ( bytes, ) ) . await ?;
115+
116+ Ok ( ( ) )
117+ }
118+
89119 async fn close ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < ( ) > {
90120 tracing:: debug!( "java.io.DataInputStream::close({:?})" , & this) ;
91121
0 commit comments