protected void updateLengthFromResponse(HttpURLConnection request) { final String xContentLengthHeader = request.getHeaderField(BlobConstants.CONTENT_LENGTH_HEADER); if (!Utility.isNullOrEmpty(xContentLengthHeader)) { this.getProperties().setLength(Long.parseLong(xContentLengthHeader)); } }
protected void updateLengthFromResponse(HttpURLConnection request) { final String xContentLengthHeader = request.getHeaderField(BlobConstants.CONTENT_LENGTH_HEADER); if (!Utility.isNullOrEmpty(xContentLengthHeader)) { this.getProperties().setLength(Long.parseLong(xContentLengthHeader)); } }
properties.setLength(pageBlobSize);
properties.setLength(pageBlobSize);
@Override public Void preProcessResponse(CloudPageBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } blob.getProperties().setLength(size); blob.updateEtagAndLastModifiedFromResponse(this.getConnection()); blob.updateSequenceNumberFromResponse(this.getConnection()); return null; } };
@Override public Void preProcessResponse(CloudPageBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } blob.getProperties().setLength(size); blob.updateEtagAndLastModifiedFromResponse(this.getConnection()); blob.updateSequenceNumberFromResponse(this.getConnection()); return null; } };
this.properties.setLength(Long.parseLong(value));
this.properties.setLength(Long.parseLong(value));
@Override public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { this.setNonExceptionedRetryableFailure(true); return null; } blob.updateEtagAndLastModifiedFromResponse(this.getConnection()); this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection())); blob.getProperties().setLength(0); return null; }
@Override public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { this.setNonExceptionedRetryableFailure(true); return null; } blob.updateEtagAndLastModifiedFromResponse(this.getConnection()); this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection())); blob.getProperties().setLength(0); return null; }
@Override public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { this.setNonExceptionedRetryableFailure(true); return null; } blob.updateEtagAndLastModifiedFromResponse(this.getConnection()); this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection())); blob.getProperties().setLength(length); blob.getProperties().setPremiumPageBlobTier(premiumBlobTier); if (premiumBlobTier != null) { blob.getProperties().setBlobTierInferred(false); } return null; }
@Override public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { this.setNonExceptionedRetryableFailure(true); return null; } blob.updateEtagAndLastModifiedFromResponse(this.getConnection()); this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection())); blob.getProperties().setLength(length); blob.getProperties().setPremiumPageBlobTier(premiumBlobTier); if (premiumBlobTier != null) { blob.getProperties().setBlobTierInferred(false); } return null; }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServer() throws StorageException, URISyntaxException, IOException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); CloudBlob blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.PAGE_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.APPEND_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerSnapshot() throws StorageException, URISyntaxException, IOException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); CloudBlob snapshot = blob.createSnapshot(); snapshot.getProperties().setContentType("application/octet-stream"); snapshot.getProperties().setLength(1024); CloudBlob blobRef = this.container.getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null); BlobTestHelper.assertAreEqual(snapshot, blobRef); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadDownloadBlobProperties() throws URISyntaxException, StorageException, IOException { final int length = 0; // 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 blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); CloudBlockBlob blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1); blockBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); // this is not set by upload (it is for page blob!), so set this manually blockBlobRef1.getProperties().setLength(length); BlobTestHelper.setBlobProperties(blockBlobRef1); BlobProperties props1 = blockBlobRef1.getProperties(); blockBlobRef1.uploadProperties(); blockBlobRef1.downloadAttributes(null, options, null); BlobProperties props2 = blockBlobRef1.getProperties(); Assert.assertEquals(props1.getLength(), props2.getLength()); BlobTestHelper.assertAreEqual(props1, props2); // by uploading/downloading the blob blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1); BlobTestHelper.setBlobProperties(blockBlobRef1); props1 = blockBlobRef1.getProperties(); blockBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); blockBlobRef1.download(new ByteArrayOutputStream(), null, options, null); props2 = blockBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); }