public void create(final long length, BlobRequestOptions options, OperationContext opContext) throws StorageException { ((CloudPageBlob) getBlob()).create(length, null, options, opContext); }
public void create(final long length, BlobRequestOptions options, OperationContext opContext) throws StorageException { ((CloudPageBlob) getBlob()).create(length, null, options, opContext); }
/** * Creates a page blob. If the blob already exists, this will replace it. To instead throw an error if the blob * already exists, use the {@link #create(long, AccessCondition, BlobRequestOptions, OperationContext)} * overload with {@link AccessCondition#generateIfNotExistsCondition()}. * @param length * A <code>long</code> which represents the size, in bytes, of the page blob. * * @throws IllegalArgumentException * If the length is not a multiple of 512. * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void create(final long length) throws StorageException { this.create(length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Creates a page blob. If the blob already exists, this will replace it. To instead throw an error if the blob * already exists, use the {@link #create(long, AccessCondition, BlobRequestOptions, OperationContext)} * overload with {@link AccessCondition#generateIfNotExistsCondition()}. * @param length * A <code>long</code> which represents the size, in bytes, of the page blob. * * @throws IllegalArgumentException * If the length is not a multiple of 512. * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void create(final long length) throws StorageException { this.create(length, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Creates a page blob using the specified request options and operation context. If the blob already exists, * this will replace it. To instead throw an error if the blob already exists, use * {@link AccessCondition#generateIfNotExistsCondition()}. * * @param length * A <code>long</code> which represents the size, in bytes, of the page blob. * @param accessCondition * An {@link AccessCondition} object which represents the access conditions for the blob. * @param options * A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudBlobClient}). * @param opContext * An {@link OperationContext} object which represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @throws IllegalArgumentException * If the length is not a multiple of 512. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void create(final long length, final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext) throws StorageException { this.create(length, null /* premiumBlobTier */, accessCondition, options, opContext); }
/** * Creates a page blob using the specified request options and operation context. If the blob already exists, * this will replace it. To instead throw an error if the blob already exists, use * {@link AccessCondition#generateIfNotExistsCondition()}. * * @param length * A <code>long</code> which represents the size, in bytes, of the page blob. * @param accessCondition * An {@link AccessCondition} object which represents the access conditions for the blob. * @param options * A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudBlobClient}). * @param opContext * An {@link OperationContext} object which represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @throws IllegalArgumentException * If the length is not a multiple of 512. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public void create(final long length, final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext) throws StorageException { this.create(length, null /* premiumBlobTier */, accessCondition, options, opContext); }
private static void populateContainer(CloudBlobContainer container, String delimiter) throws URISyntaxException, StorageException { for (int i = 1; i < 3; i++) { for (int j = 1; j < 3; j++) { for (int k = 1; k < 3; k++) { String directory = "TopDir" + i + delimiter + "MidDir" + j + delimiter + "EndDir" + k + delimiter + "EndBlob" + k; CloudPageBlob blob1 = container.getPageBlobReference(directory); blob1.create(0); } } CloudPageBlob blob2 = container.getPageBlobReference("TopDir" + i + delimiter + "Blob" + i); blob2.create(0); } }
private void doCreatePageBlob(CloudPageBlob client, BlobServiceRequestOptions opts, Exchange exchange) throws Exception { LOG.trace("Creating a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); Long pageSize = getPageBlobSize(exchange); try { client.create(pageSize, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } catch (StorageException ex) { if (ex.getHttpStatusCode() != 409) { throw ex; } } ExchangeUtil.getMessageForResponse(exchange) .setHeader(BlobServiceConstants.PAGE_BLOCK_CREATED, Boolean.TRUE); }
/** * Creates an object of BlobUtils. It creates the container and page blob if they don't exist already. * @param client Client handle for access to Azure Storage account. * @param containerName Name of container inside which we want the blob to reside. * @param blobName Name of the blob to be managed. * @param length Length of the page blob. * @throws AzureException If an Azure storage service error occurred, or when the container name or blob name is invalid. */ public BlobUtils(AzureClient client, String containerName, String blobName, long length) { this.blobClient = client.getBlobClient(); try { this.container = blobClient.getContainerReference(containerName); container.createIfNotExists(); this.blob = container.getPageBlobReference(blobName); if (!blob.exists()) { blob.create(length, AccessCondition.generateIfNotExistsCondition(), null, null); } } catch (URISyntaxException e) { LOG.error("Container name: " + containerName + " or blob name: " + blobName + " invalid.", e); throw new AzureException(e); } catch (StorageException e) { int httpStatusCode = e.getHttpStatusCode(); if (httpStatusCode == HttpStatus.CONFLICT_409) { LOG.info("The blob you're trying to create exists already.", e); } else { LOG.error("Azure Storage Exception!", e); throw new AzureException(e); } } }
private CloudPageBlob setUpPageRanges() throws StorageException, URISyntaxException, IOException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(blobLengthToUse); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); final CloudPageBlob blobRef = this.container.getPageBlobReference(blobName); blobRef.create(blobLengthToUse); // Upload page 0 ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); blobRef.uploadPages(inputStream, 0, 512); // Upload pages 2-4 inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512); blobRef.uploadPages(inputStream, 2 * 512, 3 * 512); // Upload page 6 inputStream = new ByteArrayInputStream(buffer, 3 * 512, 512); blobRef.uploadPages(inputStream, 6 * 512, 512); // Page0: 512 bytes should be the first 512 bytes of the random buffer (page 0) // Page1: 512 bytes should be 0 // Page2-4: 3 * 512 bytes should be equal to bytes (512 -> 4 * 512) of the random buffer (pages 2-4) // Page5: 512 bytes should be 0 // Page6: 512 bytes should be the 4th 512 byte segmented of the random buffer // Page7-8: 2 * 512 bytes should be 0 return blobRef; }
@Test public void testOpenOutputStreamNotAligned() throws StorageException, URISyntaxException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(8 * 512); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); final CloudPageBlob blobRef = this.container.getPageBlobReference(blobName); blobRef.create(blobLengthToUse); try { blobRef.openWriteNew(blobLengthToUse + 1); fail("Did not throw expected exception on non-512-byte-aligned offset"); } catch (IllegalArgumentException ex) { assertEquals(SR.INVALID_PAGE_BLOB_LENGTH, ex.getMessage()); } BlobOutputStream blobOutputStream = blobRef.openWriteNew(blobLengthToUse); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); try { blobOutputStream.write(inputStream, 511); blobOutputStream.close(); fail("Did not throw expected exception on non-512-byte-aligned length"); } catch (IOException ex) { assertEquals(String.format(SR.INVALID_NUMBER_OF_BYTES_IN_THE_BUFFER, 511), ex.getMessage()); } }
@Test public void testEightTBBlob() throws StorageException, URISyntaxException, IOException { CloudPageBlob blob = this.container.getPageBlobReference("blob1"); CloudPageBlob blob2 = this.container.getPageBlobReference("blob1"); long eightTb = 8L * 1024L * 1024L * 1024L * 1024L; blob.create(eightTb); assertEquals(eightTb, blob.getProperties().getLength()); blob2.downloadAttributes(); assertEquals(eightTb, blob2.getProperties().getLength()); for (ListBlobItem listBlob : this.container.listBlobs()) { CloudPageBlob listPageBlob = (CloudPageBlob)listBlob; assertEquals(eightTb, listPageBlob.getProperties().getLength()); } CloudPageBlob blob3 = this.container.getPageBlobReference("blob3"); blob3.create(1024); blob3.resize(eightTb); final Random randGenerator = new Random(); final byte[] buffer = new byte[1024]; randGenerator.nextBytes(buffer); blob.uploadPages(new ByteArrayInputStream(buffer), eightTb - 512L, 512L); ArrayList<PageRange> ranges = blob.downloadPageRanges(); assertEquals(1, ranges.size()); assertEquals(eightTb - 512L, ranges.get(0).getStartOffset()); assertEquals(eightTb - 1L, ranges.get(0).getEndOffset()); }
@Test public void testOpenOutputStream() throws URISyntaxException, StorageException, IOException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(8 * 512); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); final CloudPageBlob blobRef = this.container.getPageBlobReference(blobName); blobRef.create(blobLengthToUse); BlobOutputStream blobOutputStream = blobRef.openWriteNew(blobLengthToUse); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); blobOutputStream = blobRef.openWriteNew(blobLengthToUse); inputStream = new ByteArrayInputStream(buffer); blobOutputStream.write(inputStream, 512); inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512); blobOutputStream.write(inputStream, 3 * 512); blobOutputStream.close(); byte[] result = new byte[blobLengthToUse]; blobRef.downloadToByteArray(result, 0); int i = 0; for (; i < 4 * 512; i++) { assertEquals(buffer[i], result[i]); } for (; i < 8 * 512; i++) { assertEquals(0, result[i]); } }
private void testGetParent(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { CloudPageBlob blob = container.getPageBlobReference("Dir1" + delimiter + "Blob1"); blob.create(0); try { assertTrue(blob.exists()); assertEquals(blob.getName(), "Dir1" + delimiter + "Blob1"); CloudBlobDirectory parent = blob.getParent(); assertEquals("Dir1" + delimiter, parent.getPrefix()); } finally { blob.deleteIfExists(); } }
/** * Test requesting stored content MD5 with OpenWriteExisting(). * * @throws URISyntaxException * @throws StorageException */ @Test public void testPageOpenWriteExistingWithMD5() throws URISyntaxException, StorageException, IOException { final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob"); final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName); pageBlobRef.create(512); BlobRequestOptions options = new BlobRequestOptions(); options.setStoreBlobContentMD5(true); options.setDisableContentMD5Validation(false); try { pageBlobRef.openWriteExisting(null, options, null); fail("Expect failure due to requesting MD5 calculation"); } catch (IllegalArgumentException e) { } }
if (delimiter.equals("/")) { try { pageBlob.create(0); pageBlob.deleteIfExists(); fail("Try to create a CloudBlobDirectory/blob which has a slash in its name in the root container");
blobRef.create(blobLengthToUse); assertNull(blobRef.getProperties().getPageBlobSequenceNumber());
blob = container.getPageBlobReference(name); if (length == 0) { ((CloudPageBlob) blob).create(length, null, null, context); } else { blob.upload(getRandomDataStream(length), length, null, null, context);
@Test public void testResize() throws StorageException, URISyntaxException { CloudPageBlob blob = this.container.getPageBlobReference("blob1"); CloudPageBlob blob2 = this.container.getPageBlobReference("blob1"); blob.create(1024); assertEquals(1024, blob.getProperties().getLength()); assertNull(blob.getProperties().getPageBlobSequenceNumber()); blob2.downloadAttributes(); assertEquals(1024, blob2.getProperties().getLength()); assertNull(blob.getProperties().getPageBlobSequenceNumber()); blob2.getProperties().setContentType("text/plain"); blob2.uploadProperties(); blob.resize(2048); assertEquals(2048, blob.getProperties().getLength()); assertNotNull(blob.getProperties().getPageBlobSequenceNumber()); blob.downloadAttributes(); assertEquals("text/plain", blob.getProperties().getContentType()); assertNotNull(blob.getProperties().getPageBlobSequenceNumber()); blob2.downloadAttributes(); assertEquals(2048, blob2.getProperties().getLength()); assertNotNull(blob.getProperties().getPageBlobSequenceNumber()); }