mirror of
https://github.com/ceph/ceph
synced 2024-12-18 01:16:55 +00:00
Merge pull request #1732 from dynamike67/master
doc: Added Java Example
This commit is contained in:
commit
49033e8cd5
@ -824,6 +824,57 @@ Python Example
|
||||
ioctx.remove_object("bm")
|
||||
|
||||
|
||||
Java-Example
|
||||
------------
|
||||
|
||||
.. code-block:: java
|
||||
|
||||
import com.ceph.rados.Rados;
|
||||
import com.ceph.rados.RadosException;
|
||||
|
||||
import java.io.File;
|
||||
import com.ceph.rados.IoCTX;
|
||||
|
||||
public class CephClient {
|
||||
public static void main (String args[]){
|
||||
|
||||
try {
|
||||
Rados cluster = new Rados("admin");
|
||||
System.out.println("Created cluster handle.");
|
||||
|
||||
File f = new File("/etc/ceph/ceph.conf");
|
||||
cluster.confReadFile(f);
|
||||
System.out.println("Read the configuration file.");
|
||||
|
||||
cluster.connect();
|
||||
System.out.println("Connected to the cluster.");
|
||||
|
||||
IoCTX io = cluster.ioCtxCreate("data");
|
||||
|
||||
String oidone = "hw";
|
||||
String contentone = "Hello World!";
|
||||
io.write(oidone, contentone);
|
||||
|
||||
String oidtwo = "bm";
|
||||
String contenttwo = "Bonjour tout le monde!";
|
||||
io.write(oidtwo, contenttwo);
|
||||
|
||||
String[] objects = io.listObjects();
|
||||
for (String object: objects)
|
||||
System.out.println(object);
|
||||
|
||||
io.remove(oidone);
|
||||
io.remove(oidtwo);
|
||||
|
||||
cluster.ioCtxDestroy(io);
|
||||
|
||||
} catch (RadosException e) {
|
||||
System.out.println(e.getMessage() + ": " + e.getReturnValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Step 4: Closing Sessions
|
||||
========================
|
||||
|
Loading…
Reference in New Issue
Block a user