当前位置: 首页>>代码示例>>Java>>正文


Java CloudBlockBlob.download方法代码示例

本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlockBlob.download方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlockBlob.download方法的具体用法?Java CloudBlockBlob.download怎么用?Java CloudBlockBlob.download使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.storage.blob.CloudBlockBlob的用法示例。


在下文中一共展示了CloudBlockBlob.download方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRetryOn304

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
@Test
public void testRetryOn304() throws StorageException, IOException, URISyntaxException {
    OperationContext operationContext = new OperationContext();
    operationContext.getRetryingEventHandler().addListener(new StorageEvent<RetryingEvent>() {
        @Override
        public void eventOccurred(RetryingEvent eventArg) {
            fail("Request should not be retried.");
        }
    });

    CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
    try {
        container.create();
        CloudBlockBlob blockBlobRef = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(container, BlobType.BLOCK_BLOB,
                "originalBlob", 1024, null);
        AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition(blockBlobRef.getProperties().getEtag());
        blockBlobRef.download(new ByteArrayOutputStream(), accessCondition, null, operationContext);
        
        fail("Download should fail with a 304.");
    } catch (StorageException ex) {
        assertEquals("The condition specified using HTTP conditional header(s) is not met.", ex.getMessage());
    } finally {
        container.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:26,代码来源:SecondaryTests.java

示例2: retrieve

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
/**
 * Retrieves a file from Azure, stores it in the local file system and
 * returns its absolute path.
 * 
 * @throws StorageException
 * @throws URISyntaxException
 */
@Override
public String retrieve(String str) throws IOException,
		GeneralSecurityException, StorageException, URISyntaxException {
	String localFileName = Constants.AZURE_DIRECTORY + "/" + str + System.currentTimeMillis();
	File localCopy = new File(localFileName);
	if (!localCopy.exists()) {
		localCopy.getParentFile().mkdirs();
		localCopy.createNewFile();
	}
	// System.out.println(localCopy.getAbsolutePath());
	CloudBlockBlob blobSource = container.getBlockBlobReference(str);
	if (blobSource.exists()) {
		blobSource.download(new FileOutputStream(localCopy));
	}
	LogUtils.debug(LOG_TAG, "File " + str + " was downloaded to "
			+ Constants.AZURE_DIRECTORY + " .");
	return localFileName;
}
 
开发者ID:darshanmaiya,项目名称:MCSFS,代码行数:26,代码来源:AzureStore.java

示例3: downloadImage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
private byte[] downloadImage(CloudBlockBlob imgBlob){
  	LOG.debug("downloadImage");
  	ByteArrayOutputStream bos = new ByteArrayOutputStream();
  	try {
	imgBlob.download(bos);
} catch (StorageException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
  	return bos.toByteArray();
  }
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:12,代码来源:AzureImageStorageServiceImpl.java

示例4: downloadImage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
private byte[] downloadImage(CloudBlockBlob imgBlob){
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	try {
		imgBlob.download(bos);
	} catch (StorageException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return bos.toByteArray();
}
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:11,代码来源:AzureImageStorageServiceImpl.java

示例5: getFromAzureBlobStorage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public byte[] getFromAzureBlobStorage(String name) throws Exception {
	CloudStorageAccount storageAccount = CloudStorageAccount.parse(azureConnectionString);
	CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
	CloudBlobContainer container = blobClient.getContainerReference(containerName);
	CloudBlockBlob blob = container.getBlockBlobReference(name);

	ByteArrayOutputStream outStream = new ByteArrayOutputStream();
	blob.download(outStream);
	byte[] image = outStream.toByteArray();
	return image;
}
 
开发者ID:ritazh,项目名称:azure-s3proxy-cf-demo,代码行数:12,代码来源:PhotoLibrary.java

示例6: getFromStorageAccount

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public byte[] getFromStorageAccount(String name) throws Exception {
	CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
	CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
	CloudBlobContainer container = blobClient.getContainerReference("images");
	CloudBlockBlob blob = container.getBlockBlobReference(name);

	ByteArrayOutputStream outStream = new ByteArrayOutputStream();
	blob.download(outStream);
	byte[] image = outStream.toByteArray();
	return image;
}
 
开发者ID:adib-samples,项目名称:azure-doge,代码行数:12,代码来源:PhotoLibrary.java

示例7: main

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public static void main(String[] args) throws InvalidKeyException,
        URISyntaxException, StorageException, NoSuchAlgorithmException,
        IOException {
    Utility.printSampleStartInfo("BlobBasicsEncryption");

    // Retrieve storage account information from connection string
    // How to create a storage connection string -
    // https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
    CloudStorageAccount account = CloudStorageAccount
            .parse(Utility.storageConnectionString);
    CloudBlobClient blobClient = account.createCloudBlobClient();

    // Get a reference to a container
    // The container name must be lower case
    // Append a random UUID to the end of the container name so that
    // this sample can be run more than once in quick succession.
    CloudBlobContainer container = blobClient
            .getContainerReference("blobencryptioncontainer"
                    + UUID.randomUUID().toString().replace("-", ""));

    try {
        // Create the container if it does not exist
        container.createIfNotExists();

        int size = 5 * 1024 * 1024;
        byte[] buffer = new byte[size];

        Random rand = new Random();
        rand.nextBytes(buffer);

        CloudBlockBlob blob = container.getBlockBlobReference("blockBlob");

        // Create the IKey used for encryption.
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(1024);
        final KeyPair wrapKey = keyGen.generateKeyPair();
        RsaKey key = new RsaKey("rsaKey1", wrapKey);

        // Create the encryption policy to be used for upload.
        BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(key,
                null);

        // Set the encryption policy on the request options.
        BlobRequestOptions uploadOptions = new BlobRequestOptions();
        uploadOptions.setEncryptionPolicy(uploadPolicy);

        System.out.println("Uploading the encrypted blob.");

        // Upload the encrypted contents to the blob.
        ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
        blob.upload(inputStream, size, null, uploadOptions, null);

        // Download the encrypted blob.
        // For downloads, a resolver can be set up that will help pick the
        // key based on the key id.
        // Create the encryption policy to be used for download.
        LocalResolver resolver = new LocalResolver();
        resolver.add(key);
        BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(
                null, resolver);

        // Set the decryption policy on the request options.
        BlobRequestOptions downloadOptions = new BlobRequestOptions();
        downloadOptions.setEncryptionPolicy(downloadPolicy);

        System.out.println("Downloading the encrypted blob.");

        // Download and decrypt the encrypted contents from the blob.
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        blob.download(outputStream, null, downloadOptions, null);
    } finally {
        // Delete the container
        container.deleteIfExists();
        Utility.printSampleCompleteInfo("BlobBasicsEncryption");
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:77,代码来源:BlobGettingStarted.java

示例8: getImage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public void getImage(String name, OutputStream imageStream, long imageLength) throws Exception {
    CloudBlobContainer container = getContainer();

    CloudBlockBlob blob = container.getBlockBlobReference(name);

    if (blob.exists()) {
        blob.downloadAttributes();

        imageLength = blob.getProperties().getLength();

        blob.download(imageStream);
    }
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:14,代码来源:ImageManager.java

示例9: GetImage

import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入方法依赖的package包/类
public static void GetImage(String name, OutputStream imageStream, long imageLength) throws Exception {
    CloudBlobContainer container = getContainer();

    CloudBlockBlob blob = container.getBlockBlobReference(name);

    if(blob.exists()){
        blob.downloadAttributes();

        imageLength = blob.getProperties().getLength();

        blob.download(imageStream);
    }
}
 
开发者ID:Azure-Samples,项目名称:storage-blob-android-photo-uploader,代码行数:14,代码来源:ImageManager.java


注:本文中的com.microsoft.azure.storage.blob.CloudBlockBlob.download方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。