本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlockBlob类的典型用法代码示例。如果您正苦于以下问题:Java CloudBlockBlob类的具体用法?Java CloudBlockBlob怎么用?Java CloudBlockBlob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloudBlockBlob类属于com.microsoft.azure.storage.blob包,在下文中一共展示了CloudBlockBlob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadToAzureStorage
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的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: delete
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Override
public void delete(String blobName) throws UnableToDeleteException, FileNotFoundException {
log.debug(LOGGER_KEY + "-- Delete --" + _exchangeType);
CloudBlockBlob deleteBlob = null;
try {
deleteBlob = this.mBlobContainer.getBlockBlobReference(blobName);
if (this.config.getPostProcess().equalsIgnoreCase(PluginConstants.POST_PROCESS_DELETE)) {
boolean status = deleteBlob.deleteIfExists();
log.info(LOGGER_KEY + "Post processing Status (delete): " + status);
} else {
log.info(LOGGER_KEY + "Post processing skipped: " + this.config.getPostProcess());
}
} catch (URISyntaxException | StorageException e) {
log.error(LOGGER_KEY + e.getMessage());
throw new UnableToDeleteException("Unable to Delete Source Blob [" + blobName + "]" + e.getMessage(), e);
}
}
示例3: uploadPackageToAzureStorage
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的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);
}
示例4: 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();
}
}
示例5: listBlobsByPrefix
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Override
public Map<String, BlobMetaData> listBlobsByPrefix(String account, LocationMode mode, String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
// NOTE: this should be here: if (prefix == null) prefix = "";
// however, this is really inefficient since deleteBlobsByPrefix enumerates everything and
// then does a prefix match on the result; it should just call listBlobsByPrefix with the prefix!
logger.debug("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix);
MapBuilder<String, BlobMetaData> blobsBuilder = MapBuilder.newMapBuilder();
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
SocketAccess.doPrivilegedVoidException(() -> {
if (blobContainer.exists()) {
for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix))) {
URI uri = blobItem.getUri();
logger.trace("blob url [{}]", uri);
// uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
// this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
String blobPath = uri.getPath().substring(1 + container.length() + 1);
CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobPath);
// fetch the blob attributes from Azure (getBlockBlobReference does not do this)
// this is needed to retrieve the blob length (among other metadata) from Azure Storage
blob.downloadAttributes();
BlobProperties properties = blob.getProperties();
String name = blobPath.substring(keyPath.length());
logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength());
blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getLength()));
}
}
});
return blobsBuilder.immutableMap();
}
示例6: moveBlob
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Override
public void moveBlob(String account, LocationMode mode, String container, String sourceBlob, String targetBlob) throws URISyntaxException, StorageException {
logger.debug("moveBlob container [{}], sourceBlob [{}], targetBlob [{}]", container, sourceBlob, targetBlob);
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
CloudBlockBlob blobSource = blobContainer.getBlockBlobReference(sourceBlob);
if (blobSource.exists()) {
CloudBlockBlob blobTarget = blobContainer.getBlockBlobReference(targetBlob);
SocketAccess.doPrivilegedVoidException(() -> {
blobTarget.startCopy(blobSource);
blobSource.delete();
});
logger.debug("moveBlob container [{}], sourceBlob [{}], targetBlob [{}] -> done", container, sourceBlob, targetBlob);
}
}
示例7: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
public byte[] getImageAsArray(String imagefilename) {
byte[] b = null;
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
CloudBlockBlob imgBlob = container.getBlockBlobReference(imagefilename);
b = downloadImage(imgBlob);
} catch (URISyntaxException | StorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return b;
}
示例8: storeImage
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
public String storeImage(String IncidentId, String fileName, String contentType, byte[] fileBuffer) {
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
String imageUriString = null;
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
container.createIfNotExists();
// Set anonymous access on the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
String incidentBlob = getIncidentBlobFilename(IncidentId,fileName);
CloudBlockBlob imgBlob = container.getBlockBlobReference(incidentBlob);
imgBlob.getProperties().setContentType(contentType);
imgBlob.uploadFromByteArray(fileBuffer, 0, fileBuffer.length);
imageUriString = incidentBlob;
} catch (URISyntaxException | StorageException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return imageUriString;
}
示例9: getImageAsArray
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
public byte[] getImageAsArray(String imagefilename) {
byte[] b = null;
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
CloudBlockBlob imgBlob = container.getBlockBlobReference(imagefilename);
b = downloadImage(imgBlob);
} catch (URISyntaxException | StorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return b;
}
示例10: storeImage
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
public String storeImage(String IncidentId, String fileName, String contentType, byte[] fileBuffer) {
CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
String imageUriString = null;
// Container name must be lower case.
CloudBlobContainer container;
try {
container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
container.createIfNotExists();
// Set anonymous access on the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
String incidentBlob = getIncidentBlobFilename(IncidentId,fileName);
CloudBlockBlob imgBlob = container.getBlockBlobReference(incidentBlob);
imgBlob.getProperties().setContentType(contentType);
imgBlob.uploadFromByteArray(fileBuffer, 0, fileBuffer.length);
imageUriString = incidentBlob;
} catch (URISyntaxException | StorageException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return result
return imageUriString;
}
示例11: primeRootContainer
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient,
String accountName, String blobName, int fileSize) throws Exception {
// Create a container if it does not exist. The container name
// must be lower case.
CloudBlobContainer container = blobClient.getContainerReference("https://"
+ accountName + "/" + "$root");
container.createIfNotExists();
// Create a blob output stream.
CloudBlockBlob blob = container.getBlockBlobReference(blobName);
BlobOutputStream outputStream = blob.openOutputStream();
outputStream.write(new byte[fileSize]);
outputStream.close();
// Return a reference to the block blob object.
return blob;
}
示例12: outOfBandFolder_uncleMkdirs
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Test
public void outOfBandFolder_uncleMkdirs() throws Exception {
// NOTE: manual use of CloubBlockBlob targets working directory explicitly.
// WASB driver methods prepend working directory implicitly.
String workingDir = "user/"
+ UserGroupInformation.getCurrentUser().getShortUserName() + "/";
CloudBlockBlob blob = testAccount.getBlobReference(workingDir
+ "testFolder1/a/input/file");
BlobOutputStream s = blob.openOutputStream();
s.close();
assertTrue(fs.exists(new Path("testFolder1/a/input/file")));
Path targetFolder = new Path("testFolder1/a/output");
assertTrue(fs.mkdirs(targetFolder));
}
示例13: outOfBandFolder_parentDelete
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Test
public void outOfBandFolder_parentDelete() throws Exception {
// NOTE: manual use of CloubBlockBlob targets working directory explicitly.
// WASB driver methods prepend working directory implicitly.
String workingDir = "user/"
+ UserGroupInformation.getCurrentUser().getShortUserName() + "/";
CloudBlockBlob blob = testAccount.getBlobReference(workingDir
+ "testFolder2/a/input/file");
BlobOutputStream s = blob.openOutputStream();
s.close();
assertTrue(fs.exists(new Path("testFolder2/a/input/file")));
Path targetFolder = new Path("testFolder2/a/input");
assertTrue(fs.delete(targetFolder, true));
}
示例14: outOfBandFolder_siblingCreate
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Test
public void outOfBandFolder_siblingCreate() throws Exception {
// NOTE: manual use of CloubBlockBlob targets working directory explicitly.
// WASB driver methods prepend working directory implicitly.
String workingDir = "user/"
+ UserGroupInformation.getCurrentUser().getShortUserName() + "/";
CloudBlockBlob blob = testAccount.getBlobReference(workingDir
+ "testFolder3/a/input/file");
BlobOutputStream s = blob.openOutputStream();
s.close();
assertTrue(fs.exists(new Path("testFolder3/a/input/file")));
Path targetFile = new Path("testFolder3/a/input/file2");
FSDataOutputStream s2 = fs.create(targetFile);
s2.close();
}
示例15: outOfBandFolder_rename
import com.microsoft.azure.storage.blob.CloudBlockBlob; //导入依赖的package包/类
@Test
public void outOfBandFolder_rename() throws Exception {
// NOTE: manual use of CloubBlockBlob targets working directory explicitly.
// WASB driver methods prepend working directory implicitly.
String workingDir = "user/"
+ UserGroupInformation.getCurrentUser().getShortUserName() + "/";
CloudBlockBlob blob = testAccount.getBlobReference(workingDir
+ "testFolder4/a/input/file");
BlobOutputStream s = blob.openOutputStream();
s.close();
Path srcFilePath = new Path("testFolder4/a/input/file");
assertTrue(fs.exists(srcFilePath));
Path destFilePath = new Path("testFolder4/a/input/file2");
fs.rename(srcFilePath, destFilePath);
}