Java Code Examples for com.microsoft.azure.storage.blob.BlobOutputStream#close()
The following examples show how to use
com.microsoft.azure.storage.blob.BlobOutputStream#close() .
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: 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 2
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 3
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 4
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 5
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 6
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 6 votes |
@Test public void outOfBandFolder_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 + "testFolder4/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("testFolder4/a/input/file"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("testFolder4/a/input/file2"); fs.rename(srcFilePath, destFilePath); }
Example 7
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 6 votes |
@Test public void outOfBandFolder_parentDelete() 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 + "testFolder2/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); assertTrue(fs.exists(new Path("testFolder2/a/input/file"))); Path targetFolder = new Path("testFolder2/a/input"); assertTrue(fs.delete(targetFolder, true)); }
Example 8
Source File: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void outOfBandFolder_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 + "testFolder4/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("testFolder4/a/input/file"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("testFolder4/a/input/file2"); fs.rename(srcFilePath, destFilePath); }
Example 9
Source File: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 6 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: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void outOfBandFolder_parentDelete() 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 + "testFolder2/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); assertTrue(fs.exists(new Path("testFolder2/a/input/file"))); Path targetFolder = new Path("testFolder2/a/input"); assertTrue(fs.delete(targetFolder, true)); }
Example 11
Source File: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void outOfBandFolder_firstLevelFolderDelete() throws Exception { CloudBlockBlob blob = testAccount.getBlobReference("folderW/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); assertTrue(fs.exists(new Path("/folderW"))); assertTrue(fs.exists(new Path("/folderW/file"))); assertTrue(fs.delete(new Path("/folderW"), true)); }
Example 12
Source File: AzureStorageClient.java From azure-kusto-java with MIT License | 5 votes |
void uploadStream(InputStream inputStream, CloudBlockBlob blob) throws StorageException, IOException { // Ensure Ensure.argIsNotNull(inputStream, "inputStream"); Ensure.argIsNotNull(blob, "blob"); BlobOutputStream bos = blob.openOutputStream(); copyStream(inputStream, bos, STREAM_BUFFER_SIZE); bos.close(); }
Example 13
Source File: TestOutOfBandAzureBlobOperationsLive.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void outOfBandFolder_rename_rootLevelFiles() throws Exception { // NOTE: manual use of CloubBlockBlob targets working directory explicitly. // WASB driver methods prepend working directory implicitly. CloudBlockBlob blob = testAccount.getBlobReference("fileX"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("/fileX"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("/fileXrename"); fs.rename(srcFilePath, destFilePath); }
Example 14
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 15
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 5 votes |
@Test public void outOfBandFolder_rename_rootLevelFiles() throws Exception { // NOTE: manual use of CloubBlockBlob targets working directory explicitly. // WASB driver methods prepend working directory implicitly. CloudBlockBlob blob = testAccount.getBlobReference("fileX"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("/fileX"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("/fileXrename"); fs.rename(srcFilePath, destFilePath); }
Example 16
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 5 votes |
@Test public void outOfBandFolder_rootFileDelete() throws Exception { CloudBlockBlob blob = testAccount.getBlobReference("fileY"); BlobOutputStream s = blob.openOutputStream(); s.close(); assertTrue(fs.exists(new Path("/fileY"))); assertTrue(fs.delete(new Path("/fileY"), true)); }
Example 17
Source File: TestOutOfBandAzureBlobOperationsLive.java From big-c with Apache License 2.0 | 5 votes |
@Test public void outOfBandFolder_firstLevelFolderDelete() throws Exception { CloudBlockBlob blob = testAccount.getBlobReference("folderW/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); assertTrue(fs.exists(new Path("/folderW"))); assertTrue(fs.exists(new Path("/folderW/file"))); assertTrue(fs.delete(new Path("/folderW"), true)); }
Example 18
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 19
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 20
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(); } }