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; } }
this.downloadAttributes(accessCondition, options, opContext); length = this.getProperties().getLength();
/** * @throws StorageException * @throws URISyntaxException * @throws IOException * @throws InterruptedException */ @Test public void testPageBlobNamePlusEncodingTest() throws StorageException, URISyntaxException, IOException, InterruptedException { final int length = 1 * 1024; final CloudPageBlob originalBlob = (CloudPageBlob) BlobTestHelper.uploadNewBlob(this.container, BlobType.PAGE_BLOB, "a+b.txt", length, null); final CloudPageBlob copyBlob = this.container.getPageBlobReference(originalBlob.getName() + "copyed"); copyBlob.startCopy(originalBlob); BlobTestHelper.waitForCopy(copyBlob); copyBlob.downloadAttributes(); }
throw new IllegalArgumentException(SR.ENCRYPTION_NOT_SUPPORTED_FOR_EXISTING_BLOBS); this.downloadAttributes(accessCondition, options, opContext); length = this.getProperties().getLength();
@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()); }
BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(snapshotStream.toByteArray())); source.downloadAttributes(); snapshot.downloadAttributes(); assertFalse(source.getMetadata().get("Test").equals(snapshot.getMetadata().get("Test"))); assertEquals(copyId, copy.getProperties().getCopyState().getCopyId()); copy.downloadAttributes(); BlobProperties prop1 = copy.getProperties(); BlobProperties prop2 = snapshot.getProperties();
BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(copyStream.toByteArray())); copy.downloadAttributes(); source.downloadAttributes(); BlobProperties prop1 = copy.getProperties(); BlobProperties prop2 = source.getProperties();
source.downloadAttributes(); assertNotNull(copy.getProperties().getEtag()); assertFalse(source.getProperties().getEtag().equals(copy.getProperties().getEtag())); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(copyStream.toByteArray())); copy.downloadAttributes(); BlobProperties prop1 = copy.getProperties(); BlobProperties prop2 = source.getProperties();
@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()); }
BlobTestHelper.waitForCopy(copySas); copySas.downloadAttributes(); BlobProperties prop1 = copySas.getProperties(); BlobProperties prop2 = sasBlob.getProperties();
@Test public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, StorageException, IOException { final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob"); final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(false); options.setStoreBlobContentMD5(false); pageBlobRef.upload(srcStream, length, null, options, null); pageBlobRef.downloadAttributes(); pageBlobRef.getProperties().setContentMD5("MDAwMDAwMDA="); pageBlobRef.uploadProperties(null, options, null); try { pageBlobRef.download(new ByteArrayOutputStream(), null, options, null); fail(); } catch (StorageException ex) { assertEquals(306, ex.getHttpStatusCode()); assertEquals("InvalidMd5", ex.getErrorCode()); } options.setDisableContentMD5Validation(true); pageBlobRef.download(new ByteArrayOutputStream(), null, options, null); final CloudPageBlob pageBlobRef2 = this.container.getPageBlobReference(pageBlobName); assertNull(pageBlobRef2.getProperties().getContentMD5()); byte[] target = new byte[4]; pageBlobRef2.downloadRangeToByteArray(0L, 4L, target, 0); assertEquals("MDAwMDAwMDA=", pageBlobRef2.properties.getContentMD5()); }
@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); }
@Test public void testOpenOutputStreamNoArgs() throws URISyntaxException, StorageException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob pageBlob = this.container.getPageBlobReference(blobName); try { pageBlob.openWriteExisting(); } catch (StorageException ex) { assertEquals("The specified blob does not exist.", ex.getMessage()); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } pageBlob.openWriteNew(1024); pageBlob.openWriteExisting(); CloudPageBlob pageBlob2 = this.container.getPageBlobReference(blobName); pageBlob2.downloadAttributes(); assertEquals(1024, pageBlob2.getProperties().getLength()); assertEquals(BlobType.PAGE_BLOB, pageBlob2.getProperties().getBlobType()); }
blob2.downloadAttributes(); assertEquals(PremiumPageBlobTier.P4, blob2.getProperties().getPremiumPageBlobTier()); assertNull(blob2.getProperties().isBlobTierInferred()); blob3Ref.downloadAttributes(); assertEquals(PremiumPageBlobTier.P6, blob3Ref.getProperties().getPremiumPageBlobTier()); assertNull(blob3Ref.getProperties().isBlobTierInferred()); blob4Ref.downloadAttributes(); assertEquals(PremiumPageBlobTier.P10, blob4Ref.getProperties().getPremiumPageBlobTier()); assertNull(blob4Ref.getProperties().isBlobTierInferred()); blob5Ref.downloadAttributes(); assertEquals(PremiumPageBlobTier.P20, blob5Ref.getProperties().getPremiumPageBlobTier()); assertNull(blob5Ref.getProperties().isBlobTierInferred());
blob.create(1024); assertNull(blob.getProperties().isBlobTierInferred()); blob.downloadAttributes(); assertTrue(blob.getProperties().isBlobTierInferred()); assertEquals(PremiumPageBlobTier.P10, blob.getProperties().getPremiumPageBlobTier()); blob2.downloadAttributes(); assertEquals(PremiumPageBlobTier.P40, blob2.properties.getPremiumPageBlobTier()); assertNull(blob2.getProperties().isBlobTierInferred());
copyRef.downloadAttributes(); assertEquals(PremiumPageBlobTier.P30, copyRef.getProperties().getPremiumPageBlobTier()); assertNull(copyRef.getProperties().isBlobTierInferred());