use of com.microsoft.azure.storage.blob.ListBlobItem in project tdi-studio-se by Talend.
the class AzureFileSystem method deleteFolder.
public void deleteFolder(String folder, CloudBlobContainer container) throws StorageException, URISyntaxException {
for (ListBlobItem blobItem : container.listBlobs(folder)) {
if (blobItem instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) blobItem;
blob.delete();
} else {
if (blobItem instanceof CloudBlobDirectory)
deleteFolder(((CloudBlobDirectory) blobItem).getPrefix(), container);
}
}
}
use of com.microsoft.azure.storage.blob.ListBlobItem in project azure-iot-sdk-java by Azure.
the class DeviceManagerExportSample method main.
public static void main(String[] args) throws Exception {
System.out.println("Starting export sample...");
CloudStorageAccount storageAccount = CloudStorageAccount.parse(SampleUtils.storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference(DeviceManagerExportSample.sampleContainerName);
container.createIfNotExists();
String containerSasUri = SampleUtils.getContainerSasUri(container);
RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
JobProperties exportJob = registryManager.exportDevices(containerSasUri, excludeKeys);
while (true) {
exportJob = registryManager.getJob(exportJob.getJobId());
if (exportJob.getStatus() == JobProperties.JobStatus.COMPLETED) {
break;
}
Thread.sleep(500);
}
for (ListBlobItem blobItem : container.listBlobs()) {
if (blobItem instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) blobItem;
blob.download(new FileOutputStream(SampleUtils.exportFileLocation + blob.getName()));
}
}
System.out.println("Export job completed. Results are in " + SampleUtils.exportFileLocation);
}
use of com.microsoft.azure.storage.blob.ListBlobItem in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method deleteAllMetadataRecords.
@Override
public void deleteAllMetadataRecords(String prefix) {
if (null == prefix) {
throw new NullPointerException("prefix");
}
long start = System.currentTimeMillis();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
int total = 0;
for (ListBlobItem item : metaDir.listBlobs(prefix)) {
if (item instanceof CloudBlob) {
if (((CloudBlob) item).deleteIfExists()) {
total++;
}
}
}
LOG.debug("Metadata records deleted. recordsDeleted={} metadataFolder={} duration={}", total, prefix, (System.currentTimeMillis() - start));
} catch (StorageException e) {
LOG.info("Error deleting all metadata records. metadataFolder={}", prefix, e);
} catch (DataStoreException | URISyntaxException e) {
LOG.debug("Error deleting all metadata records. metadataFolder={}", prefix, e);
} finally {
if (null != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
use of com.microsoft.azure.storage.blob.ListBlobItem in project jackrabbit-oak by apache.
the class AzureBlobStoreBackend method getAllMetadataRecords.
@Override
public List<DataRecord> getAllMetadataRecords(String prefix) {
if (null == prefix) {
throw new NullPointerException("prefix");
}
long start = System.currentTimeMillis();
final List<DataRecord> records = Lists.newArrayList();
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
for (ListBlobItem item : metaDir.listBlobs(prefix)) {
if (item instanceof CloudBlob) {
CloudBlob blob = (CloudBlob) item;
records.add(new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(stripMetaKeyPrefix(blob.getName())), blob.getProperties().getLastModified().getTime(), blob.getProperties().getLength(), true));
}
}
LOG.debug("Metadata records read. recordsRead={} metadataFolder={} duration={}", records.size(), prefix, (System.currentTimeMillis() - start));
} catch (StorageException e) {
LOG.info("Error reading all metadata records. metadataFolder={}", prefix, e);
} catch (DataStoreException | URISyntaxException e) {
LOG.debug("Error reading all metadata records. metadataFolder={}", prefix, e);
} finally {
if (null != contextClassLoader) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
return records;
}
use of com.microsoft.azure.storage.blob.ListBlobItem in project druid by druid-io.
the class AzureStorage method emptyCloudBlobDirectory.
public List<String> emptyCloudBlobDirectory(final String containerName, final String virtualDirPath) throws StorageException, URISyntaxException {
List<String> deletedFiles = new ArrayList<>();
CloudBlobContainer container = getCloudBlobContainer(containerName);
for (ListBlobItem blobItem : container.listBlobs(virtualDirPath, true, null, null, null)) {
CloudBlob cloudBlob = (CloudBlob) blobItem;
log.info("Removing file[%s] from Azure.", cloudBlob.getName());
if (cloudBlob.deleteIfExists()) {
deletedFiles.add(cloudBlob.getName());
}
}
if (deletedFiles.isEmpty()) {
log.warn("No files were deleted on the following Azure path: [%s]", virtualDirPath);
}
return deletedFiles;
}
Aggregations