@@ -22,6 +22,7 @@ impl FileInputStream {
2222 methods : vec ! [
2323 JavaMethodProto :: new( "<init>" , "(Ljava/io/File;)V" , Self :: init, Default :: default ( ) ) ,
2424 JavaMethodProto :: new( "read" , "([B)I" , Self :: read, Default :: default ( ) ) ,
25+ JavaMethodProto :: new( "available" , "()I" , Self :: available, Default :: default ( ) ) ,
2526 JavaMethodProto :: new( "read" , "()I" , Self :: read_byte, Default :: default ( ) ) ,
2627 JavaMethodProto :: new( "close" , "()V" , Self :: close, Default :: default ( ) ) ,
2728 ] ,
@@ -50,6 +51,21 @@ impl FileInputStream {
5051 Ok ( ( ) )
5152 }
5253
54+ async fn available ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i32 > {
55+ tracing:: debug!( "java.io.FileInputStream::available({:?})" , & this) ;
56+
57+ let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
58+ let rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
59+
60+ // TODO get os buffer size
61+ let stat = rust_file. metadata ( ) . await . unwrap ( ) ;
62+ let tell = rust_file. tell ( ) . await . unwrap ( ) ;
63+
64+ let available = stat. size - tell;
65+
66+ Ok ( available as _ )
67+ }
68+
5369 async fn read ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , mut buf : ClassInstanceRef < Array < i8 > > ) -> Result < i32 > {
5470 tracing:: debug!( "java.io.FileInputStream::read({:?}, {:?})" , & this, & buf) ;
5571
0 commit comments