use of org.jclouds.azureblob.AzureBlobClient in project legacy-jclouds-examples by jclouds.
the class MainApp method main.
public static void main(String[] args) throws IOException {
if (args.length < PARAMETERS)
throw new IllegalArgumentException(INVALID_SYNTAX);
// Args
String provider = args[0];
// note that you can check if a provider is present ahead of time
checkArgument(contains(allKeys, provider), "provider %s not in supported list: %s", provider, allKeys);
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);
// Add Blob
Blob blob = blobStore.blobBuilder("test").payload("testdata").build();
blobStore.putBlob(containerName, blob);
// List Container
for (StorageMetadata resourceMd : blobStore.list()) {
if (resourceMd.getType() == StorageType.CONTAINER || resourceMd.getType() == StorageType.FOLDER) {
// Use Map API
Map<String, InputStream> containerMap = context.createInputStreamMap(resourceMd.getName());
System.out.printf(" %s: %s entries%n", resourceMd.getName(), containerMap.size());
}
}
// Use Provider API
if (context.getBackendType().getRawType().equals(RestContext.class)) {
RestContext<?, ?> rest = context.unwrap();
if (rest.getApi() instanceof S3Client) {
RestContext<S3Client, S3AsyncClient> providerContext = context.unwrap();
providerContext.getApi().getBucketLogging(containerName);
} else if (rest.getApi() instanceof SwiftClient) {
RestContext<SwiftClient, SwiftAsyncClient> providerContext = context.unwrap();
providerContext.getApi().getObjectInfo(containerName, "test");
} else if (rest.getApi() instanceof AzureBlobClient) {
RestContext<AzureBlobClient, AzureBlobAsyncClient> providerContext = context.unwrap();
providerContext.getApi().getBlobProperties(containerName, "test");
} else if (rest.getApi() instanceof AtmosClient) {
RestContext<AtmosClient, AtmosAsyncClient> providerContext = context.unwrap();
providerContext.getApi().getSystemMetadata(containerName + "/test");
}
}
} finally {
// Close connecton
context.close();
System.exit(0);
}
}
Aggregations