Skip to content

Commit f03342b

Browse files
committed
Add missing close calls
1 parent 75331d3 commit f03342b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

java_runtime/src/classes/java/io/buffered_reader.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl BufferedReader {
2222
methods: vec![
2323
JavaMethodProto::new("<init>", "(Ljava/io/Reader;)V", Self::init, Default::default()),
2424
JavaMethodProto::new("readLine", "()Ljava/lang/String;", Self::read_line, Default::default()),
25+
JavaMethodProto::new("close", "()V", Self::close, Default::default()),
2526
],
2627
fields: vec![
2728
JavaFieldProto::new("in", "Ljava/io/Reader;", Default::default()),
@@ -99,4 +100,13 @@ impl BufferedReader {
99100
result.into()
100101
})
101102
}
103+
104+
async fn close(jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>) -> Result<()> {
105+
tracing::debug!("java.io.BufferedReader::close({this:?})");
106+
107+
let r#in = jvm.get_field(&this, "in", "Ljava/io/Reader;").await?;
108+
let _: () = jvm.invoke_virtual(&r#in, "close", "()V", ()).await?;
109+
110+
Ok(())
111+
}
102112
}

java_runtime/src/classes/java/io/byte_array_output_stream.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ impl ByteArrayOutputStream {
1919
JavaMethodProto::new("<init>", "(I)V", Self::init_with_size, Default::default()),
2020
JavaMethodProto::new("write", "(I)V", Self::write, Default::default()),
2121
JavaMethodProto::new("toByteArray", "()[B", Self::to_byte_array, Default::default()),
22+
JavaMethodProto::new("close", "()V", Self::close, Default::default()),
2223
],
2324
fields: vec![
2425
JavaFieldProto::new("buf", "[B", Default::default()),
@@ -83,6 +84,12 @@ impl ByteArrayOutputStream {
8384
Ok(dest.into())
8485
}
8586

87+
async fn close(_jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>) -> Result<()> {
88+
tracing::debug!("java.io.ByteArrayOutputStream::close({this:?})");
89+
90+
Ok(())
91+
}
92+
8693
async fn ensure_capacity(jvm: &Jvm, this: &mut ClassInstanceRef<Self>, capacity: usize) -> Result<()> {
8794
let old_buf = jvm.get_field(this, "buf", "[B").await?;
8895
let current_capacity = jvm.array_length(&old_buf).await?;

0 commit comments

Comments
 (0)