geruh commented on code in PR #6081:
URL: https://github.com/apache/opendal/pull/6081#discussion_r2057327478


##########
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:
   I couldn’t find any `Operator::read_with` method that takes ReadOptions as a 
second parameter. I think we could build out the read by passing in the options 
similar to how the writes are handled.
   
   But I know there’s an open issue (#5727) about supporting the passing 
Options like this, which seems super relevant! 



-- 
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: commits-unsubscr...@opendal.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to