com.microsoft.azure.storage.blob.CloudBlockBlob Java Examples
The following examples show how to use
com.microsoft.azure.storage.blob.CloudBlockBlob.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureStorageService.java From crate with Apache License 2.0 | 7 votes |
public void writeBlob(String container, String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws URISyntaxException, StorageException, IOException { LOGGER.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {})", blobName, blobSize)); final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client(); final CloudBlobContainer blobContainer = client.v1().getContainerReference(container); final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName); try { final AccessCondition accessCondition = failIfAlreadyExists ? AccessCondition.generateIfNotExistsCondition() : AccessCondition.generateEmptyCondition(); blob.upload(inputStream, blobSize, accessCondition, null, client.v2().get()); } catch (final StorageException se) { if (failIfAlreadyExists && se.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT && StorageErrorCodeStrings.BLOB_ALREADY_EXISTS.equals(se.getErrorCode())) { throw new FileAlreadyExistsException(blobName, null, se.getMessage()); } throw se; } LOGGER.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {}) - done", blobName, blobSize)); }
Example #2
Source File: AzureStorageDeleteRuntime.java From components with Apache License 2.0 | 7 votes |
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); } } }
Example #3
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 7 votes |
private void listBlobsInDirectoryWithValidation(CloudBlobContainer cloudBlobContainer, String directoryName, Boolean zeroContent) throws URISyntaxException, StorageException { CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(directoryName); Set<String> blobsWithZeroLength = new HashSet<>(); for (ListBlobItem blobItem : blobDirectory.listBlobs()) { if (blobItem instanceof CloudBlobDirectory) { listBlobsInDirectoryWithValidation(cloudBlobContainer, ((CloudBlobDirectory) blobItem).getPrefix(), zeroContent); } else if (blobItem instanceof CloudPageBlob) { validateBlobItemLength(blobItem, zeroContent, blobsWithZeroLength); } else if (blobItem instanceof CloudBlockBlob) { validateBlobItemLength(blobItem, zeroContent, blobsWithZeroLength); } else { LOGGER.error("Azure Adls Gen 2 Cloud Storage Item that is present at URI: {} cannot be classify as CloudBlob, CloudPageBlob and " + "CloudBlockBlob. ", blobItem.getUri().getPath()); throw new TestFailException(String.format("Azure Adls Gen 2 Cloud Storage Item that is present at URI: %s cannot be classify as" + " CloudBlob, CloudPageBlob and CloudBlockBlob. ", blobItem.getUri().getPath())); } } }
Example #4
Source File: PreviewStorageAzure.java From arcusplatform with Apache License 2.0 | 7 votes |
@Override public void write(String id, byte[] image) throws IOException { executor.execute(() -> { long startTime = System.nanoTime(); CloudBlobContainer container = getContainer(id); try { CloudBlockBlob blob = container.getBlockBlobReference(id); blob.uploadFromByteArray(image, 0, image.length); VIDEO_PREVIEW_AZURE_CREATE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); } catch (Exception e) { VIDEO_PREVIEW_AZURE_CREATE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); log.error("Failed to write preview image {}", id, e); } }); }
Example #5
Source File: AzureResource.java From arcusplatform with Apache License 2.0 | 7 votes |
@Override public InputStream open() throws IOException { try { CloudBlobContainer blobContainer = blobClient.getContainerReference(container); blobContainer.createIfNotExists(); CloudBlockBlob blockBlob = blobContainer.getBlockBlobReference(blob); if (blockBlob.exists()) { return blockBlob.openInputStream(); } else { throw new IOException("Blob does not exist: " + container + ", " + blob); } } catch (Exception e) { throw new IOException("Unable to initialize blob: " + container + ", " + blob, e); } }
Example #6
Source File: PreviewStorageAzure.java From arcusplatform with Apache License 2.0 | 7 votes |
@Override public void delete(String id) throws Exception { executor.execute(() -> { long startTime = System.nanoTime(); CloudBlobContainer container = getContainer(id); try { CloudBlockBlob blob = container.getBlockBlobReference(id); blob.deleteIfExists(); VIDEO_PREVIEW_AZURE_DELETE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); } catch (Exception e) { VIDEO_PREVIEW_AZURE_DELETE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); log.error("Failed to delete preview image {}", id, e); } }); }
Example #7
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 7 votes |
@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)); }
Example #8
Source File: VideoStorageAzure.java From arcusplatform with Apache License 2.0 | 7 votes |
@Override public void delete(String storagePath) throws Exception { long startTime = System.nanoTime(); URI uri = URI.create(storagePath); try { String accountName = getAccountName(uri); CloudBlobClient client = accounts.get(accountName); if (client == null) { VIDEO_STORAGE_AZURE_BAD_ACCOUNT_NAME.inc(); throw new Exception("unknown account name: " + accountName); } CloudBlockBlob blob = new CloudBlockBlob(uri, client); blob.deleteIfExists(); VIDEO_STORAGE_AZURE_DELETE_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); } catch (Exception ex) { VIDEO_STORAGE_AZURE_DELETE_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw ex; } }
Example #9
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 7 votes |
@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(); }
Example #10
Source File: AzureStorageClient.java From azure-kusto-java with MIT License | 7 votes |
CloudBlockBlob uploadLocalFileToBlob(String filePath, String blobName, String storageUri, Boolean shouldCompress) throws URISyntaxException, StorageException, IOException { log.debug("uploadLocalFileToBlob: filePath: {}, blobName: {}, storageUri: {}", filePath, blobName, storageUri); // Ensure Ensure.fileExists(filePath); Ensure.stringIsNotBlank(blobName, "blobName"); Ensure.stringIsNotBlank(storageUri, "storageUri"); CloudBlobContainer container = new CloudBlobContainer(new URI(storageUri)); CloudBlockBlob blob = container.getBlockBlobReference(blobName); if (shouldCompress) { compressAndUploadFileToBlob(filePath, blob); } else { File file = new File(filePath); uploadFileToBlob(file, blob); } return blob; }
Example #11
Source File: AzureStorageClient.java From azure-kusto-java with MIT License | 7 votes |
CloudBlockBlob uploadStreamToBlob(InputStream inputStream, String blobName, String storageUri, boolean shouldCompress) throws IOException, URISyntaxException, StorageException { log.debug("uploadStreamToBlob: blobName: {}, storageUri: {}", blobName, storageUri); // Ensure Ensure.argIsNotNull(inputStream, "inputStream"); Ensure.stringIsNotBlank(blobName, "blobName"); Ensure.stringIsNotBlank(storageUri, "storageUri"); CloudBlobContainer container = new CloudBlobContainer(new URI(storageUri)); CloudBlockBlob blob = container.getBlockBlobReference(blobName); if (shouldCompress) { compressAndUploadStream(inputStream, blob); } else { uploadStream(inputStream, blob); } return blob; }
Example #12
Source File: CloudAnalyticsClientTests.java From azure-storage-android with Apache License 2.0 | 7 votes |
/** * 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); }
Example #13
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 7 votes |
@Test public void outOfBandSingleFile_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 + "testFolder5/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("testFolder5/a/input/file"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("testFolder5/file2"); fs.rename(srcFilePath, destFilePath); }
Example #14
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 7 votes |
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; }
Example #15
Source File: StreamingIngestClientTest.java From azure-kusto-java with MIT License | 7 votes |
@Test void IngestFromBlob_EmptyBlob_IngestClientException() throws Exception { CloudBlockBlob cloudBlockBlob = mock(CloudBlockBlob.class); String blobPath = "https://storageaccount.blob.core.windows.net/container/blob.csv"; BlobSourceInfo blobSourceInfo = new BlobSourceInfo(blobPath); BlobProperties blobProperties = mock(BlobProperties.class); when(blobProperties.getLength()).thenReturn((long) 0); doNothing().when(cloudBlockBlob).downloadAttributes(); when(cloudBlockBlob.getProperties()).thenReturn(blobProperties); IngestionClientException ingestionClientException = assertThrows(IngestionClientException.class, () -> streamingIngestClient.ingestFromBlob(blobSourceInfo, ingestionProperties, cloudBlockBlob), "Expected IngestionClientException to be thrown, but it didn't"); assertTrue(ingestionClientException.getMessage().contains("Empty blob.")); }
Example #16
Source File: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 7 votes |
@Test public void outOfBandSingleFile_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 + "testFolder5/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("testFolder5/a/input/file"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("testFolder5/file2"); fs.rename(srcFilePath, destFilePath); }
Example #17
Source File: CloudAnalyticsClientTests.java From azure-storage-android with Apache License 2.0 | 7 votes |
/** * List Logs with well defined time range * * @throws URISyntaxException * @throws StorageException * @throws IOException * @throws InterruptedException */ @Test public void testCloudAnalyticsClientListLogsStartEndTime() throws URISyntaxException, StorageException, IOException { this.container.create(); this.client.LogContainer = this.container.getName(); int numBlobs = 72; Calendar now = new GregorianCalendar(); now.add(GregorianCalendar.DAY_OF_MONTH, -3); List<String> blobNames = AnalyticsTestHelper.CreateLogs(this.container, StorageService.BLOB, 72, now, Granularity.HOUR); assertEquals(numBlobs, blobNames.size()); Calendar start = new GregorianCalendar(); start.add(GregorianCalendar.DAY_OF_MONTH, -2); Calendar end = new GregorianCalendar(); end.add(GregorianCalendar.DAY_OF_MONTH, -1); for (ListBlobItem blob : this.client.listLogBlobs(StorageService.BLOB, start.getTime(), end.getTime(), null, null, null, null)) { assertEquals(CloudBlockBlob.class, blob.getClass()); assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName())); } assertTrue(blobNames.size() == 48); }
Example #18
Source File: CloudFileTests.java From azure-storage-android with Apache License 2.0 | 7 votes |
@Test @Category(SlowTests.class) public void testCopyBlockBlobSas() throws Exception { // Create source on server. final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); try { container.create(); final CloudBlockBlob source = container.getBlockBlobReference("source"); source.getMetadata().put("Test", "value"); final String data = "String data"; source.uploadText(data, Constants.UTF8_CHARSET, null, null, null); final CloudFile destination = doCloudBlobCopy(source, data.length()); final String copyData = destination.downloadText(Constants.UTF8_CHARSET, null, null, null); assertEquals(data, copyData); } finally { container.deleteIfExists(); } }
Example #19
Source File: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 7 votes |
@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)); }
Example #20
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 7 votes |
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; }
Example #21
Source File: TestBlobService.java From jframe with Apache License 2.0 | 7 votes |
public void testUploadBlob() { try { // Define the path to a local file. final String filePath = "C:\\myimages\\myimage.jpg"; // Create or overwrite the "myimage.jpg" blob with contents from a // local file. // container.getDirectoryReference(""). CloudBlockBlob blob = container.getBlockBlobReference("myimage.jpg"); File source = new File(filePath); blob.upload(new FileInputStream(source), source.length()); } catch (Exception e) { // Output the stack trace. e.printStackTrace(); } }
Example #22
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 7 votes |
private void listBlobsInDirectory(CloudBlobContainer cloudBlobContainer, String directoryName) throws URISyntaxException, StorageException { CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(directoryName); for (ListBlobItem blobItem : blobDirectory.listBlobs()) { if (blobItem instanceof CloudBlobDirectory) { listBlobsInDirectory(cloudBlobContainer, ((CloudBlobDirectory) blobItem).getPrefix()); } else if (blobItem instanceof CloudPageBlob) { Log.log(LOGGER, format(" Azure Adls Gen 2 Cloud Page Blob is present with Name: [%s] and with bytes of content: [%d] at URI: [%s] ", ((CloudPageBlob) blobItem).getName(), ((CloudPageBlob) blobItem).getProperties().getLength(), blobItem.getUri().getPath())); } else if (blobItem instanceof CloudBlockBlob) { Log.log(LOGGER, format(" Azure Adls Gen 2 Cloud Block Blob is present with Name: [%s] and with bytes of content: [%d] at URI: [%s] ", ((CloudBlockBlob) blobItem).getName(), ((CloudBlockBlob) blobItem).getProperties().getLength(), blobItem.getUri().getPath())); } else { LOGGER.error("Azure Adls Gen 2 Cloud Storage Item that is present at URI: [{}] cannot be classify as CloudBlob, CloudPageBlob and " + "CloudBlockBlob. ", blobItem.getUri().getPath()); throw new TestFailException(String.format("Azure Adls Gen 2 Cloud Storage Item that is present at URI: [%s] cannot be classify as" + " CloudBlob, CloudPageBlob and CloudBlockBlob. ", blobItem.getUri().getPath())); } } }
Example #23
Source File: AzureCloudBlobClientActions.java From cloudbreak with Apache License 2.0 | 7 votes |
private void deleteBlobsInDirectory(CloudBlobContainer cloudBlobContainer, String directoryName) throws URISyntaxException, StorageException { CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(directoryName); for (ListBlobItem blobItem : blobDirectory.listBlobs()) { if (blobItem instanceof CloudBlobDirectory) { deleteBlobsInDirectory(cloudBlobContainer, ((CloudBlobDirectory) blobItem).getPrefix()); } else if (blobItem instanceof CloudPageBlob) { CloudPageBlob cloudPageBlob = cloudBlobContainer.getPageBlobReference(((CloudPageBlob) blobItem).getName()); cloudPageBlob.deleteIfExists(); } else if (blobItem instanceof CloudBlockBlob) { CloudBlockBlob cloudBlockBlob = cloudBlobContainer.getBlockBlobReference(((CloudBlockBlob) blobItem).getName()); cloudBlockBlob.deleteIfExists(); } } }
Example #24
Source File: AzureStorageRepository.java From hawkbit-extensions with Eclipse Public License 1.0 | 7 votes |
@Override public AbstractDbArtifact getArtifactBySha1(final String tenant, final String sha1Hash16) { try { final CloudBlockBlob blob = getBlob(tenant, sha1Hash16); if (blob == null || !blob.exists()) { return null; } LOG.info("Loading Azure Storage blob from container {} and hash {} for tenant {}", blob.getContainer().getName(), sha1Hash16, tenant); return new AzureStorageArtifact(blob, sha1Hash16, new DbArtifactHash(sha1Hash16, convertToBase16(blob.getProperties().getContentMD5()), null), blob.getProperties().getLength(), blob.getProperties().getContentType()); } catch (final URISyntaxException | StorageException e) { throw new ArtifactStoreException("Failed to load artifact into Azure storage", e); } }
Example #25
Source File: AzureStorageListReaderTest.java From components with Apache License 2.0 | 7 votes |
@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()); } }
Example #26
Source File: StreamingIngestClientTest.java From azure-kusto-java with MIT License | 7 votes |
@Test void IngestFromBlob() throws Exception { CloudBlockBlob cloudBlockBlob = mock(CloudBlockBlob.class); String blobPath = "https://storageaccount.blob.core.windows.net/container/blob.csv"; BlobSourceInfo blobSourceInfo = new BlobSourceInfo(blobPath); BlobProperties blobProperties = mock(BlobProperties.class); when(blobProperties.getLength()).thenReturn((long) 1000); BlobInputStream blobInputStream = mock(BlobInputStream.class); when(blobInputStream.read(any(byte[].class))).thenReturn(10).thenReturn(-1); doNothing().when(cloudBlockBlob).downloadAttributes(); when(cloudBlockBlob.getProperties()).thenReturn(blobProperties); when(cloudBlockBlob.openInputStream()).thenReturn(blobInputStream); OperationStatus status = streamingIngestClient.ingestFromBlob(blobSourceInfo, ingestionProperties, cloudBlockBlob).getIngestionStatusCollection().get(0).status; assertEquals(status, OperationStatus.Succeeded); verify(streamingClientMock, atLeastOnce()).executeStreamingIngest(any(String.class), any(String.class), any(InputStream.class), isNull(), any(String.class), isNull(), any(boolean.class)); }
Example #27
Source File: AzureStorageService.java From crate with Apache License 2.0 | 6 votes |
public InputStream getInputStream(String container, String blob) throws URISyntaxException, StorageException, IOException { final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client(); final CloudBlockBlob blockBlobReference = client.v1().getContainerReference(container).getBlockBlobReference(blob); LOGGER.trace(() -> new ParameterizedMessage("reading container [{}], blob [{}]", container, blob)); return blockBlobReference.openInputStream(null, null, client.v2().get()); }
Example #28
Source File: AzureBlobResource.java From camel-quarkus with Apache License 2.0 | 6 votes |
@javax.enterprise.inject.Produces @Named("azureBlobClient") public CloudBlob createBlobClient() throws Exception { StorageCredentials credentials = StorageCredentials.tryParseCredentials(System.getProperty("azurite.credentials")); URI uri = new URI(System.getProperty("azurite.blob.service.url") + "camel-test/test"); CloudBlockBlob cloudBlockBlob = new CloudBlockBlob(uri, credentials); return cloudBlockBlob; }
Example #29
Source File: AzureResource.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public boolean isFile() { try { CloudBlobContainer blobContainer = blobClient.getContainerReference(this.container); if (blobContainer.exists()) { CloudBlockBlob blockBlob = blobContainer.getBlockBlobReference(this.blob); return blockBlob.exists(); } } catch (Exception e) { logger.debug("isFile failed to lookup URI - [{}]", getUri(), e); } return false; }
Example #30
Source File: AzureFileManager.java From SEAL-Demo with MIT License | 6 votes |
/** * Delete an existing file from Azure. * @param containerName Name of the Azure Blob Container * @param destinationName File name * @throws URISyntaxException if containerName contains incorrect Uri syntax * @throws InvalidKeyException if containerName contains an invalid key * @throws StorageException if the blob client is unable to get a container reference * @throws ExecutionException if the blob client is unable to get a container reference * @throws InterruptedException if the blob client is unable to get a container reference */ public static void DeleteFile(String containerName, String destinationName) throws URISyntaxException, StorageException, ExecutionException, InterruptedException { CloudBlobContainer container = getContainer(containerName); if (!container.exists()) { throw new IllegalArgumentException("Container does not exist"); } CloudBlockBlob fileBlob = container.getBlockBlobReference(destinationName); fileBlob.deleteIfExists(); }