Java Code Examples for com.microsoft.azure.storage.blob.BlobOutputStream#write()
The following examples show how to use
com.microsoft.azure.storage.blob.BlobOutputStream#write() .
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: 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 2
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 3
Source File: TestContainerChecks.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testContainerExistAfterDoesNotExist() throws Exception { testAccount = AzureBlobStorageTestAccount.create("", EnumSet.noneOf(CreateOptions.class)); assumeNotNull(testAccount); CloudBlobContainer container = testAccount.getRealContainer(); FileSystem fs = testAccount.getFileSystem(); // Starting off with the container not there assertFalse(container.exists()); // A list shouldn't create the container and will set file system store // state to DoesNotExist try { fs.listStatus(new Path("/")); assertTrue("Should've thrown.", false); } catch (FileNotFoundException ex) { assertTrue("Unexpected exception: " + ex, ex.getMessage().contains("does not exist.")); } assertFalse(container.exists()); // Create a container outside of the WASB FileSystem container.create(); // Add a file to the container outside of the WASB FileSystem CloudBlockBlob blob = testAccount.getBlobReference("foo"); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[10]); outputStream.close(); // Make sure the file is visible assertTrue(fs.exists(new Path("/foo"))); assertTrue(container.exists()); }
Example 4
Source File: TestContainerChecks.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testContainerExistAfterDoesNotExist() throws Exception { testAccount = AzureBlobStorageTestAccount.create("", EnumSet.noneOf(CreateOptions.class)); assumeNotNull(testAccount); CloudBlobContainer container = testAccount.getRealContainer(); FileSystem fs = testAccount.getFileSystem(); // Starting off with the container not there assertFalse(container.exists()); // A list shouldn't create the container and will set file system store // state to DoesNotExist try { fs.listStatus(new Path("/")); assertTrue("Should've thrown.", false); } catch (FileNotFoundException ex) { assertTrue("Unexpected exception: " + ex, ex.getMessage().contains("does not exist.")); } assertFalse(container.exists()); // Create a container outside of the WASB FileSystem container.create(); // Add a file to the container outside of the WASB FileSystem CloudBlockBlob blob = testAccount.getBlobReference("foo"); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[10]); outputStream.close(); // Make sure the file is visible assertTrue(fs.exists(new Path("/foo"))); assertTrue(container.exists()); }
Example 5
Source File: AzureBlobStorageTestAccount.java From hadoop with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, 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(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example 6
Source File: AzureBlobStorageTestAccount.java From big-c with Apache License 2.0 | 4 votes |
public static void primePublicContainer(CloudBlobClient blobClient, String accountName, String containerName, 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(containerName); container.createIfNotExists(); // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of( SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions .setPublicAccess(BlobContainerPublicAccessType.CONTAINER); // Set the policy using the values set above. containerPermissions.getSharedAccessPolicies().put("testwasbpolicy", sasPolicy); container.uploadPermissions(containerPermissions); // Create a blob output stream. CloudBlockBlob blob = container.getBlockBlobReference(blobName); BlobOutputStream outputStream = blob.openOutputStream(); outputStream.write(new byte[fileSize]); outputStream.close(); }
Example 7
Source File: GenericTests.java From azure-storage-android with Apache License 2.0 | 4 votes |
public void testReadTimeoutIssue() throws URISyntaxException, StorageException, IOException { // part 1 byte[] buffer = BlobTestHelper.getRandomBuffer(1 * 1024 * 1024); // set the maximum execution time BlobRequestOptions options = new BlobRequestOptions(); options.setMaximumExecutionTimeInMs(5000); CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName()); String blobName = "testBlob"; final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName); blockBlobRef.setStreamWriteSizeInBytes(1 * 1024 * 1024); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); BlobOutputStream blobOutputStream = null; try { container.createIfNotExists(); blobOutputStream = blockBlobRef.openOutputStream(null, options, null); try { blobOutputStream.write(inputStream, buffer.length); } finally { blobOutputStream.close(); } assertTrue(blockBlobRef.exists()); } finally { inputStream.close(); container.deleteIfExists(); } // part 2 int length2 = 10 * 1024 * 1024; byte[] uploadBuffer2 = BlobTestHelper.getRandomBuffer(length2); CloudBlobClient blobClient2 = TestHelper.createCloudBlobClient(); CloudBlobContainer container2 = blobClient2.getContainerReference(generateRandomContainerName()); String blobName2 = "testBlob"; final CloudBlockBlob blockBlobRef2 = container2.getBlockBlobReference(blobName2); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(uploadBuffer2); try { container2.createIfNotExists(); blockBlobRef2.upload(inputStream2, length2); } finally { inputStream2.close(); container2.deleteIfExists(); } }