We use Jclouds blob storage in order to manage the Blobs in our private cload swift blob storage .
The following code demonstrates creating , writing , exploring and reading from swift using jcloud SwiftBlobStore.
package com.gmuav.playwithjcloads;import java.io.IOException;import org.jclouds.ContextBuilder;import org.jclouds.blobstore.BlobStore;import org.jclouds.blobstore.BlobStoreContext;import org.jclouds.blobstore.domain.Blob;import org.jclouds.blobstore.domain.StorageMetadata;import com.google.common.base.Charsets;import com.google.common.io.ByteSource;public class PlayWithSwift {public static void main(String[] args) throws IOException {String identity = " --- ";String credential = " --- ";String containerName = "myContainer";ByteSource payload = ByteSource.wrap("This is the Data as text ".getBytes(Charsets.UTF_8));BlobStoreContext context = ContextBuilder.newBuilder("swift").credentials(identity, credential).buildView(BlobStoreContext.class);try {// Create ContainerBlobStore blobStore = context.getBlobStore();blobStore.createContainerInLocation(null, containerName);String theBlobName = "myFolder/myData";Blob blob = blobStore.blobBuilder(theBlobName).payload(payload).contentLength(payload.size()).build();blobStore.putBlob(containerName, blob);// List Containerfor (StorageMetadata nextBlob : blobStore.list()) {System.out.println("NextBlob:" + nextBlob.getName());}Blob theRetreivedBlob = blobStore.getBlob(identity, theBlobName);String theRetValue = new String (((ByteSource)theRetreivedBlob.getPayload()).read() , Charsets.UTF_8);System.out.println("The blob data " + theRetValue);} finally {context.close();}}}
References:
jclouds-examples
אין תגובות:
הוסף רשומת תגובה