sunheyi6 commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057732004
##########
bindings/java/src/async_operator.rs:
##########
@@ -325,6 +396,76 @@ pub unsafe extern "system" fn
Java_org_apache_opendal_AsyncOperator_delete(
})
}
+async fn do_read_with_offset<'local>(
+ op: &mut Operator,
+ offset: jlong,
+ len: jlong,
+ path: String,
+) -> Result<JObject<'local>> {
+ let offset = offset as u64;
+ let len = len as u64;
+
+ let buffer = op
+ .read_with(&path)
+ .range(offset..(offset + len))
+ .await?
+ .to_bytes();
+ let env = unsafe { get_current_env() };
+ let result = env.byte_array_from_slice(&buffer)?;
+ Ok(result.into())
+}
+
+async fn do_read_with_options<'local>(
+ op: &mut Operator,
+ read_options: JObject,
+ path: String,
+) -> Result<JObject<'local>> {
+ let offset = env.get_field(read_options, "offset", "J")?.j()?;
+ let length = {
+ let jlong = env.get_field(read_options, "length", "J")?.j()?;
+ if jlong == -1 {
+ None
+ } else {
+ Some(jlong as u64)
+ }
+ };
+ let buffer_size = env.get_field(read_options, "bufferSize", "I")?.i()? as
usize;
+ let charset_name = env.get_field(read_options, "charset",
"Ljava/lang/String;")?;
+ let charset = if !charset_name.is_null() {
+ let charset_str = env.get_string(charset_name.into())?;
+ Encoding::for_label(charset_str.to_bytes()).unwrap_or(UTF_8)
+ } else {
+ UTF_8
+ };
+ let skip_new_line = env.get_field(read_options, "skipNewLine", "Z")?.z()?;
+
+ let options = ReadOptions::builder()
+ .offset(offset)
+ .length(length)
+ .buffer_size(buffer_size)
+ .charset(charset)
+ .skip_new_line(skip_new_line)
+ .build()
+ .map_err(|e| {
+ Error::new(
+ ErrorKind::Other,
+ format!("Failed to build ReadOptions: {}", e),
+ )
+ })?;
+
+ let content = op.read_with(&path, &options).map_err(|e| {
Review Comment:
ok i will take a look.Do you think this readOptions shoud be option type
like writeOptions or JObject? i'm not sure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]