public void uploadBlob(final File file, final String containerName, final String blobPath) throws IOException, StorageException, URISyntaxException { CloudBlobContainer container = getCloudBlobContainer(containerName); try (FileInputStream stream = new FileInputStream(file)) { container.getBlockBlobReference(blobPath).upload(stream, file.length()); } }
public boolean getBlobExists(String container, String blobPath) throws URISyntaxException, StorageException { return getCloudBlobContainer(container).getBlockBlobReference(blobPath).exists(); } }
public InputStream getBlobInputStream(final String containerName, final String blobPath) throws URISyntaxException, StorageException { CloudBlobContainer container = getCloudBlobContainer(containerName); return container.getBlockBlobReference(blobPath).openInputStream(); }
public long getBlobLength(final String containerName, final String blobPath) throws URISyntaxException, StorageException { return getCloudBlobContainer(containerName).getBlockBlobReference(blobPath).getProperties().getLength(); }
@Override public void run() { try { CloudBlobContainer container = blobClient.getContainerReference(azureContainer); container.createIfNotExists(); CloudBlockBlob blob = container.getBlockBlobReference(azureKey); blob.upload(new java.io.FileInputStream(localFile), localFile.length()); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (StorageException e) { throw new RuntimeException(e); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } });
@Override public void create(UUID jobId, String key, InputStream stream) { try { CloudBlobContainer reference = blobClient.getContainerReference(BLOB_CONTAINER); CloudBlockBlob blob = reference.getBlockBlobReference(createRowKey(jobId, key)); blob.upload(stream, UNKNOWN_LENGTH); } catch (StorageException | URISyntaxException | IOException e) { throw new MicrosoftStorageException("Error creating stream for job: " + jobId, e); } }
@Override public InputStream getStream(UUID jobId, String key) { try { CloudBlobContainer reference = blobClient.getContainerReference(BLOB_CONTAINER); CloudBlockBlob blob = reference.getBlockBlobReference(createRowKey(jobId, key)); return blob.openInputStream(); } catch (StorageException | URISyntaxException e) { throw new MicrosoftStorageException("Error returning stream for job: " + jobId, e); } }
CloudBlobContainer container = blobClient.getContainerReference(containerName); CloudBlob blob = container.getBlockBlobReference(blobPath);
final CloudBlob blob = container.getBlockBlobReference(blobPath);
CloudBlobClient blobClient = AzureStorageUtils.createCloudBlobClient(context, getLogger(), flowFile); CloudBlobContainer container = blobClient.getContainerReference(containerName); CloudBlob blob = container.getBlockBlobReference(blobPath);
public void uploadBlob(final File file, final String containerName, final String blobPath) throws IOException, StorageException, URISyntaxException { CloudBlobContainer container = getCloudBlobContainer(containerName); try (FileInputStream stream = new FileInputStream(file)) { CloudBlockBlob blob = container.getBlockBlobReference(blobPath); blob.upload(stream, file.length()); } }
/** * Gets the blob reference to the given blob key. * * @param blobKey * The blob key (no initial slash). * @return The blob reference. */ public CloudBlockBlob getBlobReference(String blobKey) throws Exception { return container.getBlockBlobReference( String.format(blobKey)); }
@Override protected void doRemove(String fullPath) { try { CloudBlockBlob blob = blobContainer.getBlockBlobReference(fullPath); blob.deleteIfExists(); } catch (Exception e) { throw E.unexpected(e); } }
@Override protected InputStream doGetInputStream(String fullPath) { try { CloudBlockBlob blob = blobContainer.getBlockBlobReference(fullPath); return blob.openInputStream(); } catch (Exception exception) { throw E.unexpected(exception); } } }
@Override public HashMap<String, String> getUserMetaData(String object) throws IOException { try { CloudBlockBlob blob = container.getBlockBlobReference(object); blob.downloadAttributes(); return blob.getMetadata(); } catch (Exception e) { SDFSLogger.getLog().info("unable to download attribute", e); throw new IOException(e); } }
public boolean getBlobExists(String container, String blobPath) throws URISyntaxException, StorageException { return getCloudBlobContainer(container).getBlockBlobReference(blobPath).exists(); } }
@Override public boolean fileExists(long id) throws IOException { try { String haName = EncyptUtils.encHashArchiveName(id, Main.chunkStoreEncryptionEnabled); CloudBlockBlob blob = container.getBlockBlobReference("blocks/" + haName); return blob.exists(); } catch (Exception e) { SDFSLogger.getLog().error("unable to get id", e); throw new IOException(e); } }
public static void deleteBlob(final CloudStorageAccount storageAccount, final String containerName, final String blobName) throws Exception { final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName); if (blobContainer.exists()) { final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName); blob.deleteIfExists(); } }
@Test public void testEmpty() throws URISyntaxException, StorageException, IOException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName); BlobOutputStream str = blockBlob.openOutputStream(); str.close(); CloudBlockBlob blockBlob2 = this.container.getBlockBlobReference(blobName); blockBlob2.downloadAttributes(); assertEquals(0, blockBlob2.getProperties().getLength()); ArrayList<BlockEntry> blocks = blockBlob2.downloadBlockList(BlockListingFilter.ALL, null, null, null); assertEquals(0, blocks.size()); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlockBlobDownloadToByteArray() throws URISyntaxException, StorageException, IOException { CloudBlockBlob blob = this.container.getBlockBlobReference("blob1"); BlobTestHelper.doDownloadTest(blob, 1 * 512, 2 * 512, 0); BlobTestHelper.doDownloadTest(blob, 1 * 512, 2 * 512, 1 * 512); BlobTestHelper.doDownloadTest(blob, 2 * 512, 4 * 512, 1 * 512); BlobTestHelper.doDownloadTest(blob, 5 * 1024 * 1024, 5 * 1024 * 1024, 0); BlobTestHelper.doDownloadTest(blob, 5 * 1024 * 1024, 6 * 1024 * 1024, 512); }