本文整理汇总了Java中com.microsoft.azure.storage.blob.ListBlobItem类的典型用法代码示例。如果您正苦于以下问题:Java ListBlobItem类的具体用法?Java ListBlobItem怎么用?Java ListBlobItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListBlobItem类属于com.microsoft.azure.storage.blob包,在下文中一共展示了ListBlobItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteFiles
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
@Override
public void deleteFiles(String account, LocationMode mode, String container, String path) throws URISyntaxException, StorageException {
logger.trace("delete files container [{}], path [{}]", container, path);
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
SocketAccess.doPrivilegedVoidException(() -> {
if (blobContainer.exists()) {
// We list the blobs using a flat blob listing mode
for (ListBlobItem blobItem : blobContainer.listBlobs(path, true)) {
String blobName = blobNameFromUri(blobItem.getUri());
logger.trace("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri());
deleteBlob(account, mode, container, blobName);
}
}
});
}
示例2: listBlobsByPrefix
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的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();
}
示例3: updateDiskStates
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
/**
* Updates matching disk states for given blobs
*/
private void updateDiskStates(StorageEnumContext context, StorageEnumStages next) {
if (context.diskStates.size() == 0) {
logFine(() -> "No disk states found for update");
context.subStage = next;
handleSubStage(context);
return;
}
DeferredResult.allOf(
context.diskStates.entrySet().stream().map(dse -> {
ListBlobItem blob = context.storageBlobs.remove(dse.getKey());
if (blob == null) {
logWarning("No blob found for local state: %s", dse.getKey());
return DeferredResult.completed((Operation) null);
}
return createDiskStateHelper(context, blob, dse.getValue());
}).collect(Collectors.toList()))
.whenComplete((ops, e) -> {
context.subStage = next;
handleSubStage(context);
});
}
示例4: getAzureBlobName
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
public static String getAzureBlobName(ListBlobItem blob) {
if (blob == null || blob.getUri() == null) {
return EMPTY_STR;
}
String path = blob.getUri().getPath();
if (!path.endsWith(UriUtils.URI_PATH_CHAR)) {
return UriUtils.getLastPathSegment(blob.getUri());
}
String correctedUriPath = path.substring(0, path.length() - 1);
URI correctedUri;
try {
correctedUri = new URI(correctedUriPath);
return UriUtils.getLastPathSegment(correctedUri);
} catch (URISyntaxException use) {
return UriUtils.getLastPathSegment(blob.getUri());
}
}
示例5: testGetAzureBlobName
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
@Test
public void testGetAzureBlobName () throws Throwable {
String blobName = "MyStorageBlob";
URI validBlobUri1 = new URI("http://account.blob.core.windows.net/cid/" + blobName);
ListBlobItem validBlob1 = new MockListBlobItem(validBlobUri1);
Assert.assertEquals(blobName, AzureStorageEnumerationAdapterService.getAzureBlobName(validBlob1));
URI validBLobUri2 = new URI("http://account.blob.core.windows.net/cid/" + blobName + "/");
ListBlobItem validBlob2 = new MockListBlobItem(validBLobUri2);
Assert.assertEquals(blobName, AzureStorageEnumerationAdapterService.getAzureBlobName(validBlob2));
URI invalidBlobUri = new URI("http://account.blob.core.windows.net/cid/" + blobName + "//");
ListBlobItem invalidBlob = new MockListBlobItem(invalidBlobUri);
Assert.assertEquals(EMPTY_STR, AzureStorageEnumerationAdapterService.getAzureBlobName(invalidBlob));
ListBlobItem nullUriBlob = new MockListBlobItem(null);
AzureStorageEnumerationAdapterService.getAzureBlobName(nullUriBlob);
Assert.assertEquals(EMPTY_STR, AzureStorageEnumerationAdapterService.getAzureBlobName(invalidBlob));
}
示例6: listObjects
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
/**
* For a set of remote storage objects under a remote location and a given prefix/path
* returns their properties wrapped in ObjectSummary objects
*
* @param remoteStorageLocation location, i.e. container for Azure
* @param prefix the prefix/path to list under
* @return a collection of storage summary objects
* @throws StorageProviderException Azure storage exception
*/
@Override
public StorageObjectSummaryCollection listObjects(String remoteStorageLocation, String prefix)
throws StorageProviderException
{
StorageObjectSummaryCollection storageObjectSummaries;
try
{
CloudBlobContainer container = azStorageClient.getContainerReference(remoteStorageLocation);
Iterable<ListBlobItem> listBlobItemIterable = container.listBlobs(
prefix, // List the BLOBs under this prefix
true // List the BLOBs as a flat list, i.e. do not list directories
);
storageObjectSummaries = new StorageObjectSummaryCollection(listBlobItemIterable);
}
catch (URISyntaxException | StorageException ex)
{
logger.debug("Failed to list objects: {}", ex);
throw new StorageProviderException(ex);
}
return storageObjectSummaries;
}
示例7: getSnapshotFileKeys
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
private Map<String, Long> getSnapshotFileKeys(CloudBlobContainer container, String keyPrefix) {
Map<String, Long> snapshotFiles = new HashMap<>();
try {
for (ListBlobItem item : container.listBlobs(keyPrefix, true)) {
if (item instanceof CloudPageBlob) {
CloudPageBlob cloudBlob = (CloudPageBlob) item;
snapshotFiles.put(cloudBlob.getName(), getOriginalFileSize(cloudBlob));
}
}
} catch (StorageException e) {
logger.error("Unable to retrieve metadata.", e);
// all or none
snapshotFiles = new HashMap<>();
}
return snapshotFiles;
}
示例8: readAll
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
@Override
protected void readAll(final List<Address> members, final String clustername, final Responses responses) {
if (clustername == null) {
return;
}
String prefix = sanitize(clustername);
Iterable<ListBlobItem> listBlobItems = containerReference.listBlobs(prefix);
for (ListBlobItem blobItem : listBlobItems) {
try {
// If the item is a blob and not a virtual directory.
// n.b. what an ugly API this is
if (blobItem instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) blobItem;
ByteArrayOutputStream os = new ByteArrayOutputStream(STREAM_BUFFER_SIZE);
blob.download(os);
byte[] pingBytes = os.toByteArray();
parsePingData(pingBytes, members, responses);
}
} catch (Exception t) {
log.error("Error fetching ping data.");
}
}
}
示例9: removeAll
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
@Override
protected void removeAll(String clustername) {
if (clustername == null) {
return;
}
clustername = sanitize(clustername);
Iterable<ListBlobItem> listBlobItems = containerReference.listBlobs(clustername);
for (ListBlobItem blobItem : listBlobItems) {
try {
// If the item is a blob and not a virtual directory.
if (blobItem instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) blobItem;
boolean deleted = blob.deleteIfExists();
if (deleted) {
log.trace("Deleted file '%s'.", blob.getName());
} else {
log.debug("Tried to delete file '%s' but it was already deleted.", blob.getName());
}
}
} catch (Exception e) {
log.error("Error deleting ping data for cluster '" + clustername + "'.", e);
}
}
}
示例10: deleteIfExist
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
public void deleteIfExist(RuntimeContainer runtimeContainer) {
try {
for (RemoteBlob rmtb : createRemoteBlobFilter()) {
for (ListBlobItem blob : azureStorageBlobService.listBlobs(containerName, rmtb.prefix, rmtb.include)) {
if (blob instanceof CloudBlockBlob) {
// FIXME - problem with blobs with space in name...
boolean successfulyDeleted = azureStorageBlobService.deleteBlobBlockIfExist((CloudBlockBlob) blob);
if (!successfulyDeleted) {
LOGGER.warn(messages.getMessage("warn.FaildDelete", ((CloudBlockBlob) blob).getName()));
}
}
}
}
} catch (StorageException | URISyntaxException | InvalidKeyException e) {
LOGGER.error(e.getLocalizedMessage());
if (dieOnError) {
throw new ComponentException(e);
}
}
}
示例11: testStartAsNonStartable
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
@Test
public void testStartAsNonStartable() {
try {
when(blobService.listBlobs(anyString(), anyString(), anyBoolean())).thenReturn(new Iterable<ListBlobItem>() {
@Override
public Iterator<ListBlobItem> iterator() {
return new DummyListBlobItemIterator(new ArrayList<CloudBlockBlob>());
}
});
properties.remoteBlobs = new RemoteBlobsTable("RemoteBlobsTable");
properties.remoteBlobs.include.setValue(Arrays.asList(true));
properties.remoteBlobs.prefix.setValue(Arrays.asList("dummyFilter"));
boolean startable = reader.start();
assertFalse(startable);
assertFalse(reader.advance());
} catch (InvalidKeyException | URISyntaxException | StorageException | IOException e) {
fail("should not throw " + e.getMessage());
}
}
示例12: isCorrectLogType
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
/**
* Validates that the log given is of the correct log type.
*
* @param current
* the current log
* @return whether or not the log is of the correct type.
*/
private boolean isCorrectLogType(ListBlobItem current) {
HashMap<String, String> metadata = ((CloudBlob) current).getMetadata();
String logType = metadata.get("LogType");
if (logType == null) {
return true;
}
if (this.operations.contains(LoggingOperations.READ) && logType.contains("read")) {
return true;
}
if (this.operations.contains(LoggingOperations.WRITE) && logType.contains("write")) {
return true;
}
if (this.operations.contains(LoggingOperations.DELETE) && logType.contains("delete")) {
return true;
}
return false;
}
示例13: testDownloadBlob
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
public void testDownloadBlob() {
try {
// Loop through each blob item in the container.
for (ListBlobItem blobItem : container.listBlobs()) {
// If the item is a blob, not a virtual directory.
if (blobItem instanceof CloudBlob) {
// Download the item and save it to a file with the same
// name.
CloudBlob blob = (CloudBlob) blobItem;
blob.download(new FileOutputStream("C:\\mydownloads\\" + blob.getName()));
}
}
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
示例14: testCloudAnalyticsClientListLogs
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
/**
* List all logs
*
* @throws URISyntaxException
* @throws StorageException
* @throws IOException
* @throws InterruptedException
*/
public void testCloudAnalyticsClientListLogs() throws URISyntaxException, StorageException, IOException {
this.container.create();
this.client.LogContainer = this.container.getName();
int numBlobs = 13;
Calendar now = new GregorianCalendar();
now.add(GregorianCalendar.MONTH, -13);
List<String> blobNames = AnalyticsTestHelper.CreateLogs(this.container, StorageService.BLOB, 13, now,
Granularity.MONTH);
assertEquals(numBlobs, blobNames.size());
for (ListBlobItem blob : this.client.listLogBlobs(StorageService.BLOB)) {
assertEquals(CloudBlockBlob.class, blob.getClass());
assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName()));
}
assertTrue(blobNames.size() == 0);
}
示例15: testCloudAnalyticsClientListLogsStartTime
import com.microsoft.azure.storage.blob.ListBlobItem; //导入依赖的package包/类
/**
* List Logs with open ended time range
*
* @throws URISyntaxException
* @throws StorageException
* @throws IOException
* @throws InterruptedException
*/
@Test
public void testCloudAnalyticsClientListLogsStartTime() throws URISyntaxException, StorageException, IOException {
this.container.create();
this.client.LogContainer = this.container.getName();
int numBlobs = 48;
Calendar now = new GregorianCalendar();
now.add(GregorianCalendar.DAY_OF_MONTH, -2);
List<String> blobNames = AnalyticsTestHelper.CreateLogs(this.container, StorageService.BLOB, 48, now,
Granularity.HOUR);
assertEquals(numBlobs, blobNames.size());
Calendar start = new GregorianCalendar();
start.add(GregorianCalendar.DAY_OF_MONTH, -1);
for (ListBlobItem blob : this.client.listLogBlobs(StorageService.BLOB, start.getTime(), null, null, null, null,
null)) {
assertEquals(CloudBlockBlob.class, blob.getClass());
assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName()));
}
assertTrue(blobNames.size() == 24);
}