This program builds an operator, writes a file, reads it back, inspects its metadata, and deletes it. It runs against the in-memory service with no credentials, so you can run it right after adding the dependency.
The operator holds a native resource, so close it when you are done — a try-with-resources block does this for you:
write accepts a String or byte[]; read returns byte[].
Only the service changes; the operations stay identical. The first argument is the scheme, and configuration is a Map<String, String>:
import java.util.HashMap; import java.util.Map; import org.apache.opendal.Operator; Map<String, String> conf = new HashMap<>(); conf.put("bucket", "my-bucket"); conf.put("region", "us-east-1"); try (Operator op = Operator.of("s3", conf)) { op.write("hello.txt", "Hello from S3!"); System.out.println(new String(op.read("hello.txt"))); }
Connecting to your storage covers typed config builders and credentials. Services lists the backends and their configuration keys.
The native JARs on Maven Central use the opendal dependency features in the binding's Cargo.toml, with SFTP enabled on Unix targets.
The Java layers are built in. Exposing a new Rust layer requires Java and JNI binding code.
To add a service, add its feature name, such as "services-d1", to the opendal feature list and run this from bindings/java:
./mvnw clean package -DskipTests=true
Use the resulting JARs in target/, including the JAR with your platform's classifier.
Operator runs every call synchronously. For non-blocking code, use AsyncOperator: it has the same verbs, but each returns a CompletableFuture:
import java.util.HashMap; import java.util.Map; import org.apache.opendal.AsyncOperator; Map<String, String> conf = new HashMap<>(); conf.put("bucket", "my-bucket"); conf.put("region", "us-east-1"); try (AsyncOperator op = AsyncOperator.of("s3", conf)) { op.write("hello.txt", "Hello, World!") .thenCompose(v -> op.read("hello.txt")) .thenAccept(data -> System.out.println(new String(data))) .join(); }
Call op.blocking() on an AsyncOperator to get a synchronous Operator backed by the same configuration.