Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions bindings/java/src/blocking_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,31 @@ fn intern_create_dir(env: &mut JNIEnv, op: &mut BlockingOperator, path: JString)
let path = jstring_to_string(env, &path)?;
Ok(op.create_dir(&path)?)
}

/// # Safety
///
/// This function should not be called before the Operator are ready.
#[no_mangle]
pub unsafe extern "system" fn Java_org_apache_opendal_BlockingOperator_copy(
mut env: JNIEnv,
_: JClass,
op: *mut BlockingOperator,
source_path: JString,
target_path: JString,
) {
intern_copy(&mut env, &mut *op, source_path, target_path).unwrap_or_else(|e| {
e.throw(&mut env);
})
}

fn intern_copy(
env: &mut JNIEnv,
op: &mut BlockingOperator,
source_path: JString,
target_path: JString,
) -> Result<()> {
let source_path = jstring_to_string(env, &source_path)?;
let target_path = jstring_to_string(env, &target_path)?;

Ok(op.copy(&source_path, &target_path)?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void createDir(String path) {
createDir(nativeHandle, path);
}

public void copy(String sourcePath, String targetPath) {
copy(nativeHandle, sourcePath, targetPath);
}

@Override
protected native void disposeInternal(long handle);

Expand All @@ -86,4 +90,6 @@ public void createDir(String path) {
private static native long stat(long nativeHandle, String path);

private static native long createDir(long nativeHandle, String path);

private static native long copy(long nativeHandle, String sourcePath, String targetPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ public CompletableFuture<Void> createDir(String path) {
return AsyncRegistry.take(requestId);
}

public CompletableFuture<Void> copy(String sourcePath, String targetPath) {
final long requestId = copy(nativeHandle, sourcePath, targetPath);
return AsyncRegistry.take(requestId);
}

@Override
protected native void disposeInternal(long handle);

Expand All @@ -208,4 +213,6 @@ public CompletableFuture<Void> createDir(String path) {
private static native long makeBlockingOp(long nativeHandle);

private static native long createDir(long nativeHandle, String path);

private static native long copy(long nativeHandle, String sourcePath, String targetPath);
}
41 changes: 41 additions & 0 deletions bindings/java/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,47 @@ async fn do_create_dir(op: &mut Operator, path: String) -> Result<()> {
Ok(op.create_dir(&path).await?)
}

/// # Safety
///
/// This function should not be called before the Operator are ready.
#[no_mangle]
pub unsafe extern "system" fn Java_org_apache_opendal_Operator_copy(
mut env: JNIEnv,
_: JClass,
op: *mut Operator,
source_path: JString,
target_path: JString,
) -> jlong {
intern_copy(&mut env, op, source_path, target_path).unwrap_or_else(|e| {
e.throw(&mut env);
0
})
}

fn intern_copy(
env: &mut JNIEnv,
op: *mut Operator,
source_path: JString,
target_path: JString,
) -> Result<jlong> {
let op = unsafe { &mut *op };
let id = request_id(env)?;

let source_path = jstring_to_string(env, &source_path)?;
let target_path = jstring_to_string(env, &target_path)?;

unsafe { get_global_runtime() }.spawn(async move {
let result = do_copy(op, source_path, target_path).await;
complete_future(id, result.map(|_| JValueOwned::Void))
});

Ok(id)
}

async fn do_copy(op: &mut Operator, source_path: String, target_path: String) -> Result<()> {
Ok(op.copy(&source_path, &target_path).await?)
}

/// # Safety
///
/// This function should not be called before the Operator are ready.
Expand Down
Loading