public void create(final long length, BlobRequestOptions options, OperationContext opContext) throws StorageException { ((CloudPageBlob) getBlob()).create(length, null, options, opContext); }
/** * Resizes the page blob to the specified size. * * @param size * A <code>long</code> which represents the size of the page blob, in bytes. * * @throws StorageException * If a storage service error occurred. */ public void resize(long size) throws StorageException { this.resize(size, null /* accessCondition */, null /* options */, null /* operationContext */); }
private void writePages(ByteArrayInputStream pageData, long offset, long writeLength) { final CloudPageBlob blobRef = (CloudPageBlob) this.parentBlobRef; try { blobRef.uploadPages(pageData, offset, writeLength, this.accessCondition, this.options, this.opContext); } catch (final IOException e) { this.lastError = e; } catch (final StorageException e) { this.lastError = Utility.initIOException(e); } }
private long getOriginalFileSize(CloudPageBlob pageBlobReference) throws StorageException { long size = 0; pageBlobReference.downloadAttributes(); HashMap<String, String> map = pageBlobReference.getMetadata(); if (map != null && map.size() > 0) { try { size = Long.parseLong(map.get(ORIGINAL_SIZE_KEY)); } catch (Exception e) { logger.error("File size metadata missing or is not a number."); } } return size; } }
Utility.assertNotNull("sourceBlob", sourceBlob); URI source = sourceBlob.getSnapshotQualifiedUri(); if (sourceBlob.getServiceClient() != null && sourceBlob.getServiceClient().getCredentials() != null) source = sourceBlob.getServiceClient().getCredentials().transformUri(sourceBlob.getSnapshotQualifiedUri()); return this.startCopy(source, premiumBlobTier, sourceAccessCondition, destinationAccessCondition, options, opContext);
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob source = this.container.getPageBlobReference(blobName); source.create(1024); byte[] buffer = BlobTestHelper.getRandomBuffer(512); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); source.upload(stream, buffer.length); source.getMetadata().put("Test", "value"); source.uploadMetadata(); String sasToken = copy.generateSharedAccessSignature(policy, null); CloudPageBlob copySas = new CloudPageBlob(new URI(copy.getUri().toString() + "?" + sasToken)); CloudPageBlob snapshot = (CloudPageBlob) source.createSnapshot(); CloudPageBlob sasBlob = (CloudPageBlob) sasClient.getContainerReference(container.getName()) .getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists(); String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob)); BlobTestHelper.waitForCopy(copySas); copySas.downloadAttributes(); BlobProperties prop1 = copySas.getProperties(); BlobProperties prop2 = sasBlob.getProperties(); assertEquals("value", copySas.getMetadata().get("Test")); assertEquals(copyId, copySas.getCopyState().getCopyId()); snapshot.delete(); source.delete();
source.upload(stream, buffer.length); source.getMetadata().put("Test", "value"); source.uploadMetadata(); CloudPageBlob snapshot = (CloudPageBlob) source.createSnapshot(); source.getMetadata().put("Test", "newvalue"); source.uploadMetadata(); source.getProperties().setContentMD5(null); source.upload(stream2, buffer.length); source.download(outputStream); snapshot.download(snapshotStream); BlobTestHelper.assertStreamsAreEqual(stream2, new ByteArrayInputStream(outputStream.toByteArray())); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(snapshotStream.toByteArray())); source.downloadAttributes(); snapshot.downloadAttributes(); assertFalse(source.getMetadata().get("Test").equals(snapshot.getMetadata().get("Test"))); String copyId = copy.startCopy(BlobTestHelper.defiddler(snapshot)); BlobTestHelper.waitForCopy(copy); copy.download(copyStream); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(copyStream.toByteArray()));
@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()); }
blobRef.create(blobLengthToUse); assertNull(blobRef.getProperties().getPageBlobSequenceNumber()); blobRef.uploadPages(inputStream, 0, blobLengthToUse); assertNotNull(blobRef.getProperties().getPageBlobSequenceNumber()); blobRef.clearPages(0, 256); fail("Did not throw expected exception on non-512-byte-aligned length"); blobRef.clearPages(3 * 256, 3 * 512); fail("Did not throw expected exception on non-512-byte-aligned offset"); blobRef.clearPages(3 * 512, 2 * 512); assertNotNull(blobRef.getProperties().getPageBlobSequenceNumber()); blobRef.downloadToByteArray(result, 0);
private void testCopyPageBlobIncrementalSnapshotImpl(int overload) throws URISyntaxException, StorageException, IOException, InvalidKeyException, InterruptedException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob source = this.container.getPageBlobReference(blobName); source.create(1024); source.upload(new ByteArrayInputStream(buffer), buffer.length); CloudPageBlob snapshot = (CloudPageBlob) source.createSnapshot(); .getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference(BlobTestHelper.generateRandomBlobNameWithPrefix("copy")); URI sourceUri = TestHelper.defiddler(builder.addToURI(sasSnapshotBlob.getTransformedAddress(null).getPrimaryUri())); copyId = copy.startIncrementalCopy(BlobTestHelper.defiddler(sasSnapshotBlob)); copyId = copy.startIncrementalCopy(BlobTestHelper.defiddler(sasSnapshotBlob), null, null, null); copyId = copy.startIncrementalCopy(sourceUri); copyId = copy.startIncrementalCopy(sourceUri, null, null, null); assertEquals(BlobType.PAGE_BLOB, copy.getProperties().getBlobType()); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(sourceUri.getSchemeSpecificPart(), copy.getCopyState().getSource().getSchemeSpecificPart()); assertTrue(buffer.length == copy.getCopyState().getTotalBytes()); assertTrue(buffer.length == copy.getCopyState().getBytesCopied()); assertEquals(copyId, copy.getCopyState().getCopyId()); assertTrue(copy.properties.isIncrementalCopy()); assertNotNull(copy.properties.getCopyState().getCopyDestinationSnapshotID());
assertNoWriteOperationForSnapshot(); this.create(length, premiumBlobTier, accessCondition, options, opContext); this.downloadAttributes(accessCondition, options, opContext); length = this.getProperties().getLength();
@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()); }
pageBlob.create(0); assertTrue(pageBlob.exists()); assertEquals(dir1.getContainer().getName(), pageBlob.getContainer().getName()); assertEquals(dir1.getServiceClient().getEndpoint().toString(), pageBlob.getServiceClient().getEndpoint() .toString()); assertEquals("Dir1" + delimiter + "PageBlob", pageBlob.getName()); assertEquals(new URI(container.getUri().getScheme(), container.getUri().getAuthority(), container.getUri() .getPath() + "/Dir1" + delimiter + "PageBlob", null, null), pageBlob.getUri()); CloudBlobDirectory pageParent = pageBlob.getParent(); assertEquals("Dir1" + delimiter, pageParent.getPrefix()); blockBlob.upload(BlobTestHelper.getRandomDataStream(128), 128); assertTrue(blockBlob.exists()); assertEquals(dir1.getContainer().getName(), pageBlob.getContainer().getName()); assertEquals(dir1.getServiceClient().getEndpoint().toString(), blockBlob.getServiceClient().getEndpoint() .toString()); CloudPageBlob pageSnapshot = (CloudPageBlob) pageBlob.createSnapshot(); CloudPageBlob pageSnapshotDir1 = dir1.getPageBlobReference("PageBlob", pageSnapshot.getSnapshotID()); assertEquals(pageSnapshot.getName(), pageSnapshotDir1.getName()); assertEquals(dir1.getContainer().getName(), pageSnapshotDir1.getContainer().getName()); assertEquals(dir1.getServiceClient().getEndpoint().toString(), pageSnapshotDir1.getServiceClient() .getEndpoint().toString()); assertEquals(pageSnapshot.getUri().toString(), pageSnapshotDir1.getUri().toString()); assertEquals(pageSnapshot.getParent().getPrefix(), pageSnapshotDir1.getParent().getPrefix());
source.create(1024); randGenerator.nextBytes(buffer); source.upload(new ByteArrayInputStream(buffer), buffer.length); CloudPageBlob snapshot = (CloudPageBlob) source.createSnapshot(); .getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference("copy"); builder.add(Constants.QueryConstants.SNAPSHOT, sasSnapshotBlob.snapshotID); copy.startIncrementalCopy(BlobTestHelper.defiddler(sasSnapshotBlob)); CloudPageBlob blob = (CloudPageBlob) blobItem; if (blob.getName().equals("copy") && blob.isSnapshot()) { incrementalCopyFound = true; else if (blob.getName().equals("copy")) { assertNotNull(blob.getCopyState().getCopyDestinationSnapshotID());
container.create(); CloudPageBlob source = container.getPageBlobReference("source"); source.create(1024, PremiumPageBlobTier.P10, null, null, null); String copyId = copy.startCopy(TestHelper.defiddler(source.getUri()), PremiumPageBlobTier.P30, null, null, null, null); assertEquals(BlobType.PAGE_BLOB, copy.getProperties().getBlobType()); assertEquals(PremiumPageBlobTier.P30, copy.getProperties().getPremiumPageBlobTier()); assertEquals(PremiumPageBlobTier.P10, source.getProperties().getPremiumPageBlobTier()); assertFalse(source.getProperties().isBlobTierInferred()); assertFalse(copy.getProperties().isBlobTierInferred()); assertNull(source.getProperties().getStandardBlobTier()); assertNull(source.getProperties().getRehydrationStatus()); assertNull(copy.getProperties().getStandardBlobTier()); assertNull(copy.getProperties().getRehydrationStatus()); BlobTestHelper.waitForCopy(copy); copyRef.downloadAttributes(); assertEquals(PremiumPageBlobTier.P30, copyRef.getProperties().getPremiumPageBlobTier()); assertNull(copyRef.getProperties().isBlobTierInferred()); source2.create(1024); String copyId3 = copy3.startCopy(TestHelper.defiddler(source2.getUri()), PremiumPageBlobTier.P60, null ,null ,null, null); assertEquals(BlobType.PAGE_BLOB, copy3.getProperties().getBlobType()); assertEquals(PremiumPageBlobTier.P60, copy3.getProperties().getPremiumPageBlobTier()); assertNull(source2.getProperties().getPremiumPageBlobTier()); assertNull(source2.getProperties().isBlobTierInferred()); assertFalse(copy3.getProperties().isBlobTierInferred()); assertNull(source2.getProperties().getStandardBlobTier());
assertNull(blob.getProperties().isBlobTierInferred()); blob.create(1024, PremiumPageBlobTier.P4, null, null, null); assertEquals(PremiumPageBlobTier.P4, blob.getProperties().getPremiumPageBlobTier()); assertFalse(blob.getProperties().isBlobTierInferred()); assertNull(blob.getProperties().getStandardBlobTier()); assertNull(blob.getProperties().getRehydrationStatus()); blob2.downloadAttributes(); assertEquals(PremiumPageBlobTier.P4, blob2.getProperties().getPremiumPageBlobTier()); assertNull(blob2.getProperties().isBlobTierInferred()); assertNull(blob2.getProperties().getStandardBlobTier()); assertNull(blob2.getProperties().getRehydrationStatus()); blob3.uploadFromByteArray(buffer, 0, 1024, PremiumPageBlobTier.P6, null, null, null); assertEquals(PremiumPageBlobTier.P6, blob3.getProperties().getPremiumPageBlobTier()); assertFalse(blob3.getProperties().isBlobTierInferred()); assertNull(blob3.getProperties().getStandardBlobTier()); assertNull(blob3.getProperties().getRehydrationStatus()); blob3Ref.downloadAttributes(); assertEquals(PremiumPageBlobTier.P6, blob3Ref.getProperties().getPremiumPageBlobTier()); assertNull(blob3Ref.getProperties().isBlobTierInferred()); blob4.upload(srcStream, 1024, PremiumPageBlobTier.P10, null, null, null); assertEquals(PremiumPageBlobTier.P10, blob4.getProperties().getPremiumPageBlobTier()); assertFalse(blob4.getProperties().isBlobTierInferred()); assertNull(blob4.getProperties().getStandardBlobTier()); assertNull(blob4.getProperties().getRehydrationStatus());
@Test public void testDownloadPageRangeDiffWithOffsetAndLength() throws StorageException, URISyntaxException, IOException { final CloudPageBlob blobRef = setUpPageRanges(); final CloudPageBlob snapshot = (CloudPageBlob) blobRef.createSnapshot(); // Add page 1 InputStream inputStream = new ByteArrayInputStream(BlobTestHelper.getRandomBuffer(512)); blobRef.uploadPages(inputStream, 0, 512); List<PageRangeDiff> actualPageRanges = blobRef.downloadPageRangesDiff(snapshot.getSnapshotID(), (long) 0, (long) 5 * 512, null, null, null); List<PageRangeDiff> expectedPageRanges = new ArrayList<PageRangeDiff>(); expectedPageRanges.add(new PageRangeDiff(0, 512 - 1, false)); assertEquals(expectedPageRanges.size(), actualPageRanges.size()); for (int i = 0; i < expectedPageRanges.size(); i++) { assertEquals(expectedPageRanges.get(i).getStartOffset(), actualPageRanges.get(i).getStartOffset()); assertEquals(expectedPageRanges.get(i).getEndOffset(), actualPageRanges.get(i).getEndOffset()); assertEquals(expectedPageRanges.get(i).isCleared(), actualPageRanges.get(i).isCleared()); } }
@Test public void testUploadDownloadBlobProperties() throws URISyntaxException, StorageException, IOException { final int length = 512; // do this to make sure the set MD5 can be compared without an exception being thrown BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(true); // with explicit upload/download of properties String pageBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); CloudPageBlob pageBlobRef1 = this.container.getPageBlobReference(pageBlobName1); pageBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); BlobTestHelper.setBlobProperties(pageBlobRef1); BlobProperties props1 = pageBlobRef1.getProperties(); pageBlobRef1.uploadProperties(); pageBlobRef1.downloadAttributes(null, options, null); BlobProperties props2 = pageBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); // by uploading/downloading the blob pageBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); pageBlobRef1 = this.container.getPageBlobReference(pageBlobName1); BlobTestHelper.setBlobProperties(pageBlobRef1); props1 = pageBlobRef1.getProperties(); pageBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); pageBlobRef1.download(new ByteArrayOutputStream(), null, options, null); props2 = pageBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); }
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob blob = container.getPageBlobReference(blobName); blob.create(1024); assertNull(blob.getProperties().isBlobTierInferred()); blob.downloadAttributes(); assertTrue(blob.getProperties().isBlobTierInferred()); assertEquals(PremiumPageBlobTier.P10, blob.getProperties().getPremiumPageBlobTier()); blob.uploadPremiumPageBlobTier(PremiumPageBlobTier.P40); assertEquals(PremiumPageBlobTier.P40, blob.properties.getPremiumPageBlobTier()); assertFalse(blob.getProperties().isBlobTierInferred()); assertNull(blob.getProperties().getStandardBlobTier()); assertNull(blob.getProperties().getRehydrationStatus()); blob2.downloadAttributes(); assertEquals(PremiumPageBlobTier.P40, blob2.properties.getPremiumPageBlobTier()); assertNull(blob2.getProperties().isBlobTierInferred()); if (blob.getName().equals(blobName) && !pageBlobWithTierFound) { assertNull(blob3.getProperties().isBlobTierInferred()); assertNull(blob3.getProperties().getStandardBlobTier()); assertNull(blob3.getProperties().getRehydrationStatus()); pageBlobWithTierFound = true; } else if (blob.getName().equals(blobName)) { fail("Page blob found twice"); blob4.create(256 * (long)Constants.GB); blob4.uploadPremiumPageBlobTier(PremiumPageBlobTier.P6);