String identity = args[1];
String credential = args[2];
String containerName = args[3];
// Init
BlobStoreContext context = ContextBuilder.newBuilder(provider)
.credentials(identity, credential)
.buildView(BlobStoreContext.class);
try {
// Create Container
BlobStore blobStore = context.getBlobStore();
blobStore.createContainerInLocation(null, containerName);
String blobName = "test";
ByteSource payload = ByteSource.wrap("testdata".getBytes(Charsets.UTF_8));
// List Container Metadata
for (StorageMetadata resourceMd : blobStore.list()) {
if (containerName.equals(resourceMd.getName())) {
System.out.println(resourceMd);
}
}
// Add Blob
Blob blob = blobStore.blobBuilder(blobName)
.payload(payload)
.contentLength(payload.size())
.build();
blobStore.putBlob(containerName, blob);
// Use Provider API
ApiMetadata apiMetadata = context.unwrap().getProviderMetadata().getApiMetadata();
Object object = null;
if (apiMetadata instanceof S3ApiMetadata) {
S3Client api = context.unwrapApi(S3Client.class);
object = api.headObject(containerName, blobName);
} else if (apiMetadata instanceof SwiftApiMetadata) {
SwiftClient api = context.unwrapApi(SwiftClient.class);
object = api.getObjectInfo(containerName, blobName);
} else if (apiMetadata instanceof AzureBlobApiMetadata) {
RestContext<AzureBlobClient, ?> providerContext = context.unwrap();
object = providerContext.getApi().getBlobProperties(containerName, blobName);
} else if (apiMetadata instanceof AtmosApiMetadata) {
AtmosClient api = context.unwrapApi(AtmosClient.class);
object = api.headFile(containerName + "/" + blobName);
}
if (object != null) {
System.out.println(object);
}
} finally {
// Close connecton
context.close();
System.exit(0);
}
}