Search in sources :

Example 26 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project druid by druid-io.

the class AzureStorage method uploadBlob.

public void uploadBlob(final File file, final String containerName, final String blobPath) throws IOException, StorageException, URISyntaxException {
    CloudBlobContainer container = getCloudBlobContainer(containerName);
    try (FileInputStream stream = new FileInputStream(file)) {
        CloudBlockBlob blob = container.getBlockBlobReference(blobPath);
        blob.upload(stream, file.length());
    }
}
Also used : CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) FileInputStream(java.io.FileInputStream)

Example 27 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project elasticsearch by elastic.

the class AzureStorageServiceImpl method getInputStream.

@Override
public InputStream getInputStream(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
    logger.trace("reading container [{}], blob [{}]", container, blob);
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlockBlob blockBlobReference = client.getContainerReference(container).getBlockBlobReference(blob);
    return SocketAccess.doPrivilegedException(blockBlobReference::openInputStream);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 28 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project elasticsearch by elastic.

the class AzureStorageServiceImpl method blobExists.

@Override
public boolean blobExists(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
    // Container name must be lower case.
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);
    if (blobContainer.exists()) {
        CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
        return SocketAccess.doPrivilegedException(azureBlob::exists);
    }
    return false;
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 29 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceComponentConfigurationTest method testClientWithoutCredentialsPublicRead.

@Test
public void testClientWithoutCredentialsPublicRead() throws Exception {
    CloudBlockBlob client = new CloudBlockBlob(URI.create("https://camelazure.blob.core.windows.net/container/blob"));
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("azureBlobClient", client);
    BlobServiceComponent component = new BlobServiceComponent(context);
    BlobServiceEndpoint endpoint = (BlobServiceEndpoint) component.createEndpoint("azure-blob://camelazure/container/blob?azureBlobClient=#azureBlobClient&publicForRead=true");
    assertTrue(endpoint.getConfiguration().isPublicForRead());
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 30 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceComponentConfigurationTest method testCreateEndpointWithMinConfigForClientOnly.

@Test
public void testCreateEndpointWithMinConfigForClientOnly() throws Exception {
    CloudBlockBlob client = new CloudBlockBlob(URI.create("https://camelazure.blob.core.windows.net/container/blob"), newAccountKeyCredentials());
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("azureBlobClient", client);
    BlobServiceComponent component = new BlobServiceComponent(context);
    BlobServiceEndpoint endpoint = (BlobServiceEndpoint) component.createEndpoint("azure-blob://camelazure/container/blob?azureBlobClient=#azureBlobClient");
    doTestCreateEndpointWithMinConfig(endpoint, true);
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Aggregations

CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)42 Test (org.junit.Test)17 StorageException (com.microsoft.azure.storage.StorageException)11 Path (org.apache.hadoop.fs.Path)11 URISyntaxException (java.net.URISyntaxException)10 BlobOutputStream (com.microsoft.azure.storage.blob.BlobOutputStream)9 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)9 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)8 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileNotFoundException (java.io.FileNotFoundException)5 BlockEntry (com.microsoft.azure.storage.blob.BlockEntry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 JndiRegistry (org.apache.camel.impl.JndiRegistry)4 URI (java.net.URI)3 InvalidKeyException (java.security.InvalidKeyException)3 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)2