Java Code Examples for com.microsoft.azure.storage.blob.CloudBlockBlob#openOutputStream()

The following examples show how to use com.microsoft.azure.storage.blob.CloudBlockBlob#openOutputStream() . 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 vote down vote up
@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 2
Source File: AzureBlobStorageTestAccount.java    From big-c with Apache License 2.0 7 votes vote down vote up
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: AzureBlobStorageTestAccount.java    From hadoop with Apache License 2.0 7 votes vote down vote up
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 4
Source File: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 7 votes vote down vote up
@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: TestOutOfBandAzureBlobOperationsLive.java    From big-c with Apache License 2.0 7 votes vote down vote up
@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 6
Source File: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 7 votes vote down vote up
@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 7
Source File: TestOutOfBandAzureBlobOperationsLive.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: TestOutOfBandAzureBlobOperationsLive.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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 9
Source File: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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 10
Source File: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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 11
Source File: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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 12
Source File: TestOutOfBandAzureBlobOperationsLive.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: TestOutOfBandAzureBlobOperationsLive.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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 15
Source File: TestOutOfBandAzureBlobOperationsLive.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: TestContainerChecks.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: AzureStorageClient.java    From azure-kusto-java with MIT License 5 votes vote down vote up
void compressAndUploadStream(InputStream inputStream, CloudBlockBlob blob) throws StorageException, IOException {
    // Ensure
    Ensure.argIsNotNull(inputStream, "inputStream");
    Ensure.argIsNotNull(blob, "blob");

    BlobOutputStream bos = blob.openOutputStream();
    GZIPOutputStream gzout = new GZIPOutputStream(bos);
    copyStream(inputStream, gzout, GZIP_BUFFER_SIZE);
    gzout.close();
}
 
Example 18
Source File: AzureStorageClient.java    From azure-kusto-java with MIT License 5 votes vote down vote up
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 19
Source File: AzureBlobStorageTestAccount.java    From big-c with Apache License 2.0 4 votes vote down vote up
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: AzureBlobStorageTestAccount.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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();
}