@@ -57,12 +57,11 @@ impl RandomAccessFile {
5757
5858 let write = mode. contains ( 'w' ) ;
5959
60- let rust_file = context. open ( & name, write) . await ;
61- if rust_file. is_err ( ) {
62- // TODO correct error handling
60+ let fd_id = context. open ( & name, write) . await ;
61+ if fd_id. is_err ( ) {
6362 return Err ( jvm. exception ( "java/io/FileNotFoundException" , "File not found" ) . await ) ;
6463 }
65- let fd = FileDescriptor :: from_file ( jvm, rust_file . unwrap ( ) ) . await ?;
64+ let fd = FileDescriptor :: from_fd ( jvm, fd_id . unwrap ( ) ) . await ?;
6665 jvm. put_field ( & mut this, "fd" , "Ljava/io/FileDescriptor;" , fd) . await ?;
6766
6867 Ok ( ( ) )
@@ -103,7 +102,7 @@ impl RandomAccessFile {
103102
104103 async fn read_offset_length (
105104 jvm : & Jvm ,
106- _ : & mut RuntimeContext ,
105+ context : & mut RuntimeContext ,
107106 this : ClassInstanceRef < Self > ,
108107 mut buf : ClassInstanceRef < Array < i8 > > ,
109108 offset : i32 ,
@@ -112,7 +111,7 @@ impl RandomAccessFile {
112111 tracing:: debug!( "java.io.RandomAccessFile::read({:?}, {:?}, {:?}, {:?})" , & this, & buf, & offset, & length) ;
113112
114113 let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
115- let mut rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
114+ let mut rust_file = FileDescriptor :: file ( jvm, context , fd) . await ?;
116115
117116 let mut rust_buf = vec ! [ 0 ; length as usize ] ;
118117 let read = rust_file. read ( & mut rust_buf) . await . unwrap ( ) ;
@@ -133,7 +132,7 @@ impl RandomAccessFile {
133132
134133 async fn write_offset_length (
135134 jvm : & Jvm ,
136- _ : & mut RuntimeContext ,
135+ context : & mut RuntimeContext ,
137136 this : ClassInstanceRef < Self > ,
138137 buf : ClassInstanceRef < Array < i8 > > ,
139138 offset : i32 ,
@@ -142,7 +141,7 @@ impl RandomAccessFile {
142141 tracing:: debug!( "java.io.RandomAccessFile::write({:?}, {:?}, {:?}, {:?})" , & this, & buf, & offset, & length) ;
143142
144143 let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
145- let mut rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
144+ let mut rust_file = FileDescriptor :: file ( jvm, context , fd) . await ?;
146145
147146 let mut rust_buf = vec ! [ 0 ; length as usize ] ;
148147 jvm. array_raw_buffer ( & buf) . await ?. read ( offset as _ , & mut rust_buf) . unwrap ( ) ;
@@ -151,44 +150,44 @@ impl RandomAccessFile {
151150 Ok ( ( ) )
152151 }
153152
154- async fn seek ( jvm : & Jvm , _ : & mut RuntimeContext , this : ClassInstanceRef < Self > , pos : i64 ) -> Result < ( ) > {
153+ async fn seek ( jvm : & Jvm , context : & mut RuntimeContext , this : ClassInstanceRef < Self > , pos : i64 ) -> Result < ( ) > {
155154 tracing:: debug!( "java.io.RandomAccessFile::seek({:?}, {:?})" , & this, & pos) ;
156155
157156 let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
158- let mut rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
157+ let mut rust_file = FileDescriptor :: file ( jvm, context , fd) . await ?;
159158
160159 rust_file. seek ( pos as _ ) . await . unwrap ( ) ;
161160
162161 Ok ( ( ) )
163162 }
164163
165- async fn set_length ( jvm : & Jvm , _ : & mut RuntimeContext , this : ClassInstanceRef < Self > , new_length : i64 ) -> Result < ( ) > {
164+ async fn set_length ( jvm : & Jvm , context : & mut RuntimeContext , this : ClassInstanceRef < Self > , new_length : i64 ) -> Result < ( ) > {
166165 tracing:: debug!( "java.io.RandomAccessFile::setLength({:?}, {:?})" , & this, & new_length) ;
167166
168167 let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
169- let mut rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
168+ let mut rust_file = FileDescriptor :: file ( jvm, context , fd) . await ?;
170169
171170 rust_file. set_len ( new_length as _ ) . await . unwrap ( ) ;
172171
173172 Ok ( ( ) )
174173 }
175174
176- async fn length ( jvm : & Jvm , _ : & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i64 > {
175+ async fn length ( jvm : & Jvm , context : & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i64 > {
177176 tracing:: debug!( "java.io.RandomAccessFile::length({:?})" , & this) ;
178177
179178 let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
180- let rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
179+ let rust_file = FileDescriptor :: file ( jvm, context , fd) . await ?;
181180
182181 let len = rust_file. metadata ( ) . await . unwrap ( ) . size ;
183182
184183 Ok ( len as i64 )
185184 }
186185
187- async fn get_file_pointer ( jvm : & Jvm , _ : & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i64 > {
186+ async fn get_file_pointer ( jvm : & Jvm , context : & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < i64 > {
188187 tracing:: debug!( "java.io.RandomAccessFile::getFilePointer({:?})" , & this) ;
189188
190189 let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
191- let rust_file = FileDescriptor :: file ( jvm, fd) . await ?;
190+ let rust_file = FileDescriptor :: file ( jvm, context , fd) . await ?;
192191
193192 let pos = rust_file. tell ( ) . await . unwrap ( ) ;
194193
@@ -203,9 +202,12 @@ impl RandomAccessFile {
203202 Ok ( fd)
204203 }
205204
206- async fn close ( _jvm : & Jvm , _ : & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < ( ) > {
205+ async fn close ( jvm : & Jvm , context : & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < ( ) > {
207206 tracing:: debug!( "java.io.RandomAccessFile::close({:?})" , & this) ;
208207
208+ let fd = jvm. get_field ( & this, "fd" , "Ljava/io/FileDescriptor;" ) . await ?;
209+ FileDescriptor :: close ( jvm, context, fd) . await ?;
210+
209211 Ok ( ( ) )
210212 }
211213}
0 commit comments