Java Code Examples for com.microsoft.azure.storage.blob.CloudBlockBlob#downloadAttributes()
The following examples show how to use
com.microsoft.azure.storage.blob.CloudBlockBlob#downloadAttributes() .
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: PreviewStorageAzure.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public byte[] read(String id) throws IOException { long startTime = System.nanoTime(); CloudBlobContainer container = getContainer(id); try { CloudBlockBlob blob = container.getBlockBlobReference(id); if (!blob.exists()) return null; blob.downloadAttributes(); int imageSize = (int) blob.getProperties().getLength(); byte[] image = new byte[imageSize]; blob.downloadToByteArray(image, 0); VIDEO_PREVIEW_AZURE_DOWNLOAD_SUCCESS.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); return image; } catch (Exception e) { VIDEO_PREVIEW_AZURE_DOWNLOAD_FAIL.update(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); throw new IOException("Failed to read image " + id); } }
Example 2
Source File: AzureStorageClient.java From azure-kusto-java with MIT License | 5 votes |
long getBlobSize(String blobPath) throws StorageException, URISyntaxException { Ensure.stringIsNotBlank(blobPath, "blobPath"); CloudBlockBlob blockBlob = new CloudBlockBlob(new URI(blobPath)); blockBlob.downloadAttributes(); return blockBlob.getProperties().getLength(); }
Example 3
Source File: StreamingIngestClient.java From azure-kusto-java with MIT License | 5 votes |
IngestionResult ingestFromBlob(BlobSourceInfo blobSourceInfo, IngestionProperties ingestionProperties, CloudBlockBlob cloudBlockBlob) throws IngestionClientException, IngestionServiceException, StorageException { String blobPath = blobSourceInfo.getBlobPath(); cloudBlockBlob.downloadAttributes(); if (cloudBlockBlob.getProperties().getLength() == 0) { String message = "Empty blob."; log.error(message); throw new IngestionClientException(message); } InputStream stream = cloudBlockBlob.openInputStream(); StreamSourceInfo streamSourceInfo = new StreamSourceInfo(stream, false, blobSourceInfo.getSourceId()); streamSourceInfo.setCompressionType(AzureStorageClient.getCompression(blobPath)); return ingestFromStream(streamSourceInfo, ingestionProperties); }
Example 4
Source File: TestBlobDataValidation.java From hadoop with Apache License 2.0 | 4 votes |
private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception { assumeNotNull(testAccount); // Write a test file. String testFileKey = "testFile"; Path testFilePath = new Path("/" + testFileKey); OutputStream outStream = testAccount.getFileSystem().create(testFilePath); outStream.write(new byte[] { 5, 15 }); outStream.close(); // Check that we stored/didn't store the MD5 field as configured. CloudBlockBlob blob = testAccount.getBlobReference(testFileKey); blob.downloadAttributes(); String obtainedMd5 = blob.getProperties().getContentMD5(); if (expectMd5Stored) { assertNotNull(obtainedMd5); } else { assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5); } // Mess with the content so it doesn't match the MD5. String newBlockId = Base64.encode(new byte[] { 55, 44, 33, 22 }); blob.uploadBlock(newBlockId, new ByteArrayInputStream(new byte[] { 6, 45 }), 2); blob.commitBlockList(Arrays.asList(new BlockEntry[] { new BlockEntry( newBlockId, BlockSearchMode.UNCOMMITTED) })); // Now read back the content. If we stored the MD5 for the blob content // we should get a data corruption error. InputStream inStream = testAccount.getFileSystem().open(testFilePath); try { byte[] inBuf = new byte[100]; while (inStream.read(inBuf) > 0){ //nothing; } inStream.close(); if (expectMd5Stored) { fail("Should've thrown because of data corruption."); } } catch (IOException ex) { if (!expectMd5Stored) { throw ex; } StorageException cause = (StorageException)ex.getCause(); assertNotNull(cause); assertTrue("Unexpected cause: " + cause, cause.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MD5)); } }
Example 5
Source File: TestBlobDataValidation.java From big-c with Apache License 2.0 | 4 votes |
private void testStoreBlobMd5(boolean expectMd5Stored) throws Exception { assumeNotNull(testAccount); // Write a test file. String testFileKey = "testFile"; Path testFilePath = new Path("/" + testFileKey); OutputStream outStream = testAccount.getFileSystem().create(testFilePath); outStream.write(new byte[] { 5, 15 }); outStream.close(); // Check that we stored/didn't store the MD5 field as configured. CloudBlockBlob blob = testAccount.getBlobReference(testFileKey); blob.downloadAttributes(); String obtainedMd5 = blob.getProperties().getContentMD5(); if (expectMd5Stored) { assertNotNull(obtainedMd5); } else { assertNull("Expected no MD5, found: " + obtainedMd5, obtainedMd5); } // Mess with the content so it doesn't match the MD5. String newBlockId = Base64.encode(new byte[] { 55, 44, 33, 22 }); blob.uploadBlock(newBlockId, new ByteArrayInputStream(new byte[] { 6, 45 }), 2); blob.commitBlockList(Arrays.asList(new BlockEntry[] { new BlockEntry( newBlockId, BlockSearchMode.UNCOMMITTED) })); // Now read back the content. If we stored the MD5 for the blob content // we should get a data corruption error. InputStream inStream = testAccount.getFileSystem().open(testFilePath); try { byte[] inBuf = new byte[100]; while (inStream.read(inBuf) > 0){ //nothing; } inStream.close(); if (expectMd5Stored) { fail("Should've thrown because of data corruption."); } } catch (IOException ex) { if (!expectMd5Stored) { throw ex; } StorageException cause = (StorageException)ex.getCause(); assertNotNull(cause); assertTrue("Unexpected cause: " + cause, cause.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MD5)); } }