Skip to content

Commit d793fc9

Browse files
committed
mark/reset for bytearrayinputstream
1 parent a894f8d commit d793fc9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ impl ByteArrayInputStream {
2222
JavaMethodProto::new("read", "()I", Self::read_byte, Default::default()),
2323
JavaMethodProto::new("close", "()V", Self::close, Default::default()),
2424
JavaMethodProto::new("skip", "(J)J", Self::skip, Default::default()),
25+
JavaMethodProto::new("mark", "(I)V", Self::mark, Default::default()),
2526
JavaMethodProto::new("reset", "()V", Self::reset, Default::default()),
2627
],
2728
fields: vec![
2829
JavaFieldProto::new("buf", "[B", Default::default()),
2930
JavaFieldProto::new("pos", "I", Default::default()),
3031
JavaFieldProto::new("count", "I", Default::default()),
32+
JavaFieldProto::new("mark", "I", Default::default()),
3133
],
3234
}
3335
}
@@ -145,11 +147,19 @@ impl ByteArrayInputStream {
145147
Ok(len_to_skip)
146148
}
147149

150+
async fn mark(jvm: &Jvm, _: &mut RuntimeContext, mut this: ClassInstanceRef<Self>, readlimit: i32) -> Result<()> {
151+
tracing::debug!("java.io.ByteArrayInputStream::mark({:?}, {:?})", &this, readlimit);
152+
153+
jvm.put_field(&mut this, "mark", "I", readlimit).await?;
154+
155+
Ok(())
156+
}
157+
148158
async fn reset(jvm: &Jvm, _: &mut RuntimeContext, mut this: ClassInstanceRef<Self>) -> Result<()> {
149159
tracing::debug!("java.io.ByteArrayInputStream::reset({:?})", &this);
150160

151-
// TODO mark position
152-
jvm.put_field(&mut this, "pos", "I", 0).await?;
161+
let mark: i32 = jvm.get_field(&this, "mark", "I").await?;
162+
jvm.put_field(&mut this, "pos", "I", mark).await?;
153163

154164
Ok(())
155165
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl InputStream {
2222
JavaMethodProto::new_abstract("read", "()I", Default::default()),
2323
JavaMethodProto::new_abstract("close", "()V", Default::default()),
2424
JavaMethodProto::new("skip", "(J)J", Self::skip, Default::default()),
25+
JavaMethodProto::new("mark", "(I)V", Self::mark, Default::default()),
2526
JavaMethodProto::new("reset", "()V", Self::reset, Default::default()),
2627
],
2728
fields: vec![],
@@ -53,6 +54,12 @@ impl InputStream {
5354
Ok(n)
5455
}
5556

57+
async fn mark(_jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>, readlimit: i32) -> Result<()> {
58+
tracing::debug!("java.io.InputStream::mark({:?}, {:?})", &this, readlimit);
59+
60+
Ok(())
61+
}
62+
5663
async fn reset(jvm: &Jvm, _: &mut RuntimeContext, this: ClassInstanceRef<Self>) -> Result<()> {
5764
tracing::debug!("java.io.InputStream::reset({:?})", &this);
5865

0 commit comments

Comments
 (0)