Xuanwo commented on code in PR #1894:
URL: 
https://github.com/apache/incubator-opendal/pull/1894#discussion_r1162218239


##########
bindings/java/src/lib.rs:
##########
@@ -137,6 +120,69 @@ pub unsafe extern "system" fn 
Java_org_apache_opendal_Operator_read<'local>(
     output
 }
 
+/// # Safety
+///
+/// This function should not be called before the Operator are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Operator_stat(
+    mut env: JNIEnv,
+    _class: JClass,
+    ptr: *mut BlockingOperator,
+    file: JString,
+) -> jlong {
+    let op = &mut *ptr;
+    let file: String = env
+        .get_string(&file)
+        .expect("Couldn't get java string!")
+        .into();
+    let metadata = op.stat(&file).unwrap();
+    Box::into_raw(Box::new(metadata)) as jlong
+}
+
+/// # Safety
+///
+/// This function should not be called before the Stat are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Metadata_isFile(
+    mut _env: JNIEnv,
+    _class: JClass,
+    ptr: *mut opendal::Metadata,
+) -> jboolean {
+    let metadata = &mut *ptr;
+    metadata.is_file() as jboolean
+}
+
+/// # Safety
+///
+/// This function should not be called before the Stat are ready.
+#[no_mangle]
+pub unsafe extern "system" fn 
Java_org_apache_opendal_Metadata_getContentLength(
+    mut _env: JNIEnv,
+    _class: JClass,
+    ptr: *mut opendal::Metadata,
+) -> jlong {
+    let metadata = &mut *ptr;
+    metadata.content_length() as jlong
+}
+
+/// # Safety
+///
+/// This function should not be called before the Stat are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Metadata_freeStat(

Review Comment:
   How about using `freeMetadata`?



##########
bindings/java/src/lib.rs:
##########
@@ -88,6 +65,12 @@ pub unsafe extern "system" fn 
Java_org_apache_opendal_Operator_freeOperator(
     _class: JClass,
     ptr: *mut Operator,
 ) {
+    if ptr.is_null() {
+        // The pointer is null, nothing to free

Review Comment:
   We should panic here to let user know: It's wrong to input NULL pointer into 
opendal's API.



##########
bindings/java/src/lib.rs:
##########
@@ -137,6 +120,69 @@ pub unsafe extern "system" fn 
Java_org_apache_opendal_Operator_read<'local>(
     output
 }
 
+/// # Safety
+///
+/// This function should not be called before the Operator are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Operator_stat(
+    mut env: JNIEnv,
+    _class: JClass,
+    ptr: *mut BlockingOperator,
+    file: JString,
+) -> jlong {
+    let op = &mut *ptr;
+    let file: String = env
+        .get_string(&file)
+        .expect("Couldn't get java string!")
+        .into();
+    let metadata = op.stat(&file).unwrap();
+    Box::into_raw(Box::new(metadata)) as jlong
+}
+
+/// # Safety
+///
+/// This function should not be called before the Stat are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Metadata_isFile(
+    mut _env: JNIEnv,
+    _class: JClass,
+    ptr: *mut opendal::Metadata,
+) -> jboolean {
+    let metadata = &mut *ptr;
+    metadata.is_file() as jboolean
+}
+
+/// # Safety
+///
+/// This function should not be called before the Stat are ready.
+#[no_mangle]
+pub unsafe extern "system" fn 
Java_org_apache_opendal_Metadata_getContentLength(
+    mut _env: JNIEnv,
+    _class: JClass,
+    ptr: *mut opendal::Metadata,
+) -> jlong {
+    let metadata = &mut *ptr;
+    metadata.content_length() as jlong
+}
+
+/// # Safety
+///
+/// This function should not be called before the Stat are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Metadata_freeStat(
+    mut _env: JNIEnv,
+    _class: JClass,
+    ptr: *mut opendal::Metadata,
+) {
+    if ptr.is_null() {
+        // The pointer is null, nothing to free

Review Comment:
   The same. Please panic here.



##########
bindings/java/src/lib.rs:
##########
@@ -188,3 +234,27 @@ fn build_operator(
 
     Ok(op)
 }
+
+fn convert_map(env: &mut JNIEnv, params: &JObject) -> HashMap<String, String> {

Review Comment:
   We don't need this for now. Please remove it. Let's focus on `memory` 
service first.



##########
bindings/java/src/main/java/org/apache/opendal/Metadata.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.opendal;
+
+import io.questdb.jar.jni.JarJniLoader;
+
+public class Metadata {
+
+    public static final String ORG_APACHE_OPENDAL_RUST_LIBS = 
"/org/apache/opendal/rust/libs";
+
+    public static final String OPENDAL_JAVA = "opendal_java";

Review Comment:
   Since we only use this value in `JarJniLoader.loadLib`, maybe we can write 
them directly? And don't need to be treated as `public static final` of class 
`Metadata`.



##########
bindings/java/src/main/java/org/apache/opendal/Metadata.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.opendal;
+
+import io.questdb.jar.jni.JarJniLoader;
+
+public class Metadata {
+
+    public static final String ORG_APACHE_OPENDAL_RUST_LIBS = 
"/org/apache/opendal/rust/libs";
+
+    public static final String OPENDAL_JAVA = "opendal_java";
+
+    long statPtr;

Review Comment:
   Since we don't have other ptr inside `Metadata` class, how about using `ptr` 
instead?



-- 
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]

Reply via email to