本文整理汇总了Java中com.microsoft.azure.storage.CloudStorageAccount类的典型用法代码示例。如果您正苦于以下问题:Java CloudStorageAccount类的具体用法?Java CloudStorageAccount怎么用?Java CloudStorageAccount使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloudStorageAccount类属于com.microsoft.azure.storage包,在下文中一共展示了CloudStorageAccount类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToAzureStorage
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
/**
* Upload image file to Azure storage with specified name.
*
* @param file image file object
* @param fileName specified file name
* @return relative path of the created image blob
*/
public String uploadToAzureStorage(ApplicationContext applicationContext, MultipartFile file, String fileName) {
String uri = null;
try {
CloudStorageAccount storageAccount =
(CloudStorageAccount) applicationContext.getBean("cloudStorageAccount");
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
setupContainer(blobClient, this.thumbnailImageContainer);
CloudBlobContainer originalImageContainer = setupContainer(blobClient, this.originalImageContainer);
if (originalImageContainer != null) {
CloudBlockBlob blob = originalImageContainer.getBlockBlobReference(fileName);
blob.upload(file.getInputStream(), file.getSize());
uri = blob.getUri().getPath();
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Error uploading image: " + e.getMessage());
}
return uri;
}
示例2: uploadPackageToAzureStorage
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
@Test
public void uploadPackageToAzureStorage() throws Exception {
final MSDeployArtifactHandlerImpl handler = new MSDeployArtifactHandlerImpl(mojo);
final CloudStorageAccount storageAccount = mock(CloudStorageAccount.class);
final CloudBlobClient blobClient = mock(CloudBlobClient.class);
doReturn(blobClient).when(storageAccount).createCloudBlobClient();
final CloudBlobContainer blobContainer = mock(CloudBlobContainer.class);
doReturn(blobContainer).when(blobClient).getContainerReference(anyString());
doReturn(true).when(blobContainer)
.createIfNotExists(any(BlobContainerPublicAccessType.class), isNull(), isNull());
final CloudBlockBlob blob = mock(CloudBlockBlob.class);
doReturn(blob).when(blobContainer).getBlockBlobReference(anyString());
doNothing().when(blob).upload(any(FileInputStream.class), anyLong());
doReturn(new URI("http://blob")).when(blob).getUri();
final File file = new File("pom.xml");
final String packageUri = handler.uploadPackageToAzureStorage(file, storageAccount, "blob");
assertSame("http://blob", packageUri);
}
示例3: connectToAzTable
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
/***
*
* @param azStorageConnStr
* @param tableName
* @param l
* @return
*/
public CloudTable connectToAzTable(String azStorageConnStr, String tableName) {
CloudTable cloudTable = null;
try {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(azStorageConnStr);
// Create the table client
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Create a cloud table object for the table.
cloudTable = tableClient.getTableReference(tableName);
} catch (Exception e)
{
logger.warn("Exception in connectToAzTable: "+tableName, e);
}
return cloudTable;
}
示例4: createClient
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
void createClient(AzureStorageSettings azureStorageSettings) {
try {
logger.trace("creating new Azure storage client using account [{}], key [{}]",
azureStorageSettings.getAccount(), azureStorageSettings.getKey());
String storageConnectionString =
"DefaultEndpointsProtocol=https;"
+ "AccountName=" + azureStorageSettings.getAccount() + ";"
+ "AccountKey=" + azureStorageSettings.getKey();
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient client = storageAccount.createCloudBlobClient();
// Register the client
this.clients.put(azureStorageSettings.getAccount(), client);
} catch (Exception e) {
logger.error("can not create azure storage client: {}", e.getMessage());
}
}
示例5: createStorageAccountWithInvalidConnectionString
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
@Test
public void createStorageAccountWithInvalidConnectionString() {
System.setProperty(CONNECTION_STRING_PROPERTY, INVALID_CONNECTION_STRING);
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(StorageAutoConfiguration.class);
context.refresh();
CloudStorageAccount cloudStorageAccount = null;
try {
cloudStorageAccount = context.getBean(CloudStorageAccount.class);
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(BeanCreationException.class);
}
assertThat(cloudStorageAccount).isNull();
}
System.clearProperty(CONNECTION_STRING_PROPERTY);
}
示例6: setUpStorageAccount
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
try {
CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
// Create a blob service client
CloudBlobClient blobClient = account.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(containerName);
container.createIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// Include public access in the permissions object
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
// Set the permissions on the container
container.uploadPermissions(containerPermissions);
return container;
} catch (StorageException | URISyntaxException | InvalidKeyException e) {
throw new RuntimeException(e);
}
}
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:19,代码来源:ManageLinuxWebAppStorageAccountConnection.java
示例7: getCloudBlobContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
private CloudBlobContainer getCloudBlobContainer(String accountName, String accountKey, String containerName) {
CloudBlobContainer container = null;
if (StringUtils.isNotBlank(containerName)) {
final String storageConnectionString = "DefaultEndpointsProtocol=https"
+ ";AccountName=" + accountName
+ ";AccountKey=" + accountKey;
try {
final CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient serviceClient = account.createCloudBlobClient();
container = serviceClient.getContainerReference(containerName);
container.createIfNotExists();
} catch (StorageException | URISyntaxException | InvalidKeyException e) {
logger.error("Error connecting to container for account {} and container name {}", accountName, containerName, e);
}
}
return container;
}
示例8: Entry
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
/**
* Ctor.
* @param params Parameters
* @param exit Exit criteria
*/
public Entry(final Params params, final Exit exit) {
try {
final CloudBlobContainer container = CloudStorageAccount.parse(
new AzureStorageCredentials(
params.account(), params.key(), true
).connectionString()
).createCloudBlobClient().getContainerReference(params.container());
container.createIfNotExists();
this.storage = new AuthenticatedStorage(
params.username(), params.password(), params.realm(),
new AzureBlobStorage(container)
);
} catch (final InvalidKeyException | URISyntaxException
| StorageException e) {
throw new IllegalStateException(e);
}
this.path = params.path();
this.port = params.port();
this.exit = exit;
}
示例9: AzureNotebookRepo
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
public AzureNotebookRepo(ZeppelinConfiguration conf)
throws URISyntaxException, InvalidKeyException, StorageException {
this.conf = conf;
user = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_USER);
shareName = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_SHARE);
CloudStorageAccount account = CloudStorageAccount.parse(
conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING));
CloudFileClient client = account.createCloudFileClient();
CloudFileShare share = client.getShareReference(shareName);
share.createIfNotExists();
CloudFileDirectory userDir = StringUtils.isBlank(user) ?
share.getRootDirectoryReference() :
share.getRootDirectoryReference().getDirectoryReference(user);
userDir.createIfNotExists();
rootDir = userDir.getDirectoryReference("notebook");
rootDir.createIfNotExists();
}
示例10: init
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
@Override
public void init() throws Exception {
super.init();
// Validate configuration
// Can throw IAEs
this.validateConfiguration();
try {
StorageCredentials credentials = new StorageCredentialsAccountAndKey(storage_account_name, storage_access_key);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, use_https);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
containerReference = blobClient.getContainerReference(container);
boolean created = containerReference.createIfNotExists();
if (created) {
log.info("Created container named '%s'.", container);
} else {
log.debug("Using existing container named '%s'.", container);
}
} catch (Exception ex) {
log.error("Error creating a storage client! Check your configuration.");
throw ex;
}
}
示例11: testCreateContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
@Before
public void testCreateContainer() {
try {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container.
// The container name must be lower case
container = blobClient.getContainerReference(containerName);
// Create the container if it does not exist.
container.createIfNotExists();
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
示例12: create
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
public TableClient create() {
try {
final CloudStorageAccount storageAccount =
new CloudStorageAccount(azureTableConfiguration.getStorageCredentialsAccountAndKey(), true);
final CloudTableClient cloudTableClient = storageAccount.createCloudTableClient();
final TableRequestOptions defaultOptions = new TableRequestOptions();
defaultOptions.setRetryPolicyFactory(new RetryLinearRetry(
Ints.checkedCast(azureTableConfiguration.getRetryInterval().toMilliseconds()),
azureTableConfiguration.getRetryAttempts()));
defaultOptions.setTimeoutIntervalInMs(Ints.checkedCast(azureTableConfiguration.getTimeout().toMilliseconds()));
cloudTableClient.setDefaultRequestOptions(defaultOptions);
return new TableClient(cloudTableClient);
} catch (URISyntaxException err) {
LOGGER.error("Failed to create a TableClient", err);
throw new IllegalArgumentException(err);
}
}
示例13: validateWasbFileSystem
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
private void validateWasbFileSystem(FileSystem fileSystem, String fileSystemType) throws URISyntaxException, InvalidKeyException, StorageException {
String accountName = fileSystem.getParameter(WasbFileSystemConfiguration.ACCOUNT_NAME, String.class);
String accountKey = fileSystem.getParameter(WasbFileSystemConfiguration.ACCOUNT_KEY, String.class);
String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey;
CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer containerReference = blobClient.getContainerReference(TEST_CONTAINER + System.nanoTime());
try {
containerReference.createIfNotExists();
containerReference.delete();
} catch (StorageException e) {
if (e.getCause() instanceof UnknownHostException) {
throw new CloudConnectorException("The provided account does not belong to a valid storage account");
}
}
}
示例14: getLogDataTable
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
/**
* For the Azure Log Store, the underlying table to use
*
* @param storageConnectionString
*
* @return
*
* @throws URISyntaxException
* @throws StorageException
* @throws InvalidKeyException
*/
@Provides
@Named("logdata")
public CloudTable getLogDataTable(@Named("azure.storage-connection-string") String storageConnectionString,
@Named("azure.logging-table")
String logTableName) throws URISyntaxException, StorageException, InvalidKeyException
{
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the table client.
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Create the table if it doesn't exist.
CloudTable table = tableClient.getTableReference(logTableName);
table.createIfNotExists();
return table;
}
示例15: getContainer
import com.microsoft.azure.storage.CloudStorageAccount; //导入依赖的package包/类
private CloudBlobContainer getContainer() throws Exception {
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount
.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
Timber.d(blobClient.getEndpoint().toString());
// Get a reference to a container.
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference(CONTAINER_NAME);
return container;
}