本文整理汇总了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();
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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");
}
}
示例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);
}
}
示例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);
}
}