@Override public Integer postProcessResponse(HttpURLConnection connection, CloudFile file, CloudFileClient client, OperationContext context, Integer storageObject) throws Exception { final Boolean validateMD5 = !options.getDisableContentMD5Validation() && !Utility.isNullOrEmpty(this.getContentMD5()); final String contentLength = connection.getHeaderField(Constants.HeaderConstants.CONTENT_LENGTH); final long expectedLength = Long.parseLong(contentLength); Logger.info(context, String.format(SR.CREATING_NETWORK_STREAM, expectedLength)); final NetworkInputStream streamRef = new NetworkInputStream(connection.getInputStream(), expectedLength); try { // writeToOutputStream will update the currentRequestByteCount on this request in case a retry // is needed and download should resume from that point final StreamMd5AndLength descriptor = Utility.writeToOutputStream(streamRef, outStream, -1, false, validateMD5, context, options, true, this, this.getCurrentDescriptor()); // length was already checked by the NetworkInputStream, now check Md5 if (validateMD5 && !this.getContentMD5().equals(descriptor.getMd5())) { throw new StorageException(StorageErrorCodeStrings.INVALID_MD5, String.format( SR.FILE_HASH_MISMATCH, this.getContentMD5(), descriptor.getMd5()), Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } } finally { // Close the stream and return. Closing an already closed stream is harmless. So its fine to try // to drain the response and close the stream again in the executor. streamRef.close(); } return null; }
@Override public Integer postProcessResponse(HttpURLConnection connection, CloudFile file, CloudFileClient client, OperationContext context, Integer storageObject) throws Exception { final Boolean validateMD5 = !options.getDisableContentMD5Validation() && !Utility.isNullOrEmpty(this.getContentMD5()); final String contentLength = connection.getHeaderField(Constants.HeaderConstants.CONTENT_LENGTH); final long expectedLength = Long.parseLong(contentLength); Logger.info(context, String.format(SR.CREATING_NETWORK_STREAM, expectedLength)); final NetworkInputStream streamRef = new NetworkInputStream(connection.getInputStream(), expectedLength); try { // writeToOutputStream will update the currentRequestByteCount on this request in case a retry // is needed and download should resume from that point final StreamMd5AndLength descriptor = Utility.writeToOutputStream(streamRef, outStream, -1, false, validateMD5, context, options, this, this.getCurrentDescriptor()); // length was already checked by the NetworkInputStream, now check Md5 if (validateMD5 && !this.getContentMD5().equals(descriptor.getMd5())) { throw new StorageException(StorageErrorCodeStrings.INVALID_MD5, String.format( SR.FILE_HASH_MISMATCH, this.getContentMD5(), descriptor.getMd5()), Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } } finally { // Close the stream and return. Closing an already closed stream is harmless. So its fine to try // to drain the response and close the stream again in the executor. streamRef.close(); } return null; }
/** * Creates an instance of the <code>FileRequestOptions</code> class by copying values from another * <code>FileRequestOptions</code> instance. * * @param other * A {@link FileRequestOptions} object which represents the file request options to copy. */ public FileRequestOptions(final FileRequestOptions other) { super(other); if (other != null) { this.setConcurrentRequestCount(other.getConcurrentRequestCount()); this.setDisableContentMD5Validation(other.getDisableContentMD5Validation()); this.setStoreFileContentMD5(other.getStoreFileContentMD5()); this.setUseTransactionalContentMD5(other.getUseTransactionalContentMD5()); } }
/** * Creates an instance of the <code>FileRequestOptions</code> class by copying values from another * <code>FileRequestOptions</code> instance. * * @param other * A {@link FileRequestOptions} object which represents the file request options to copy. */ public FileRequestOptions(final FileRequestOptions other) { super(other); if (other != null) { this.setConcurrentRequestCount(other.getConcurrentRequestCount()); this.setDisableContentMD5Validation(other.getDisableContentMD5Validation()); this.setStoreFileContentMD5(other.getStoreFileContentMD5()); this.setUseTransactionalContentMD5(other.getUseTransactionalContentMD5()); } }
/** * Applies defaults to the options passed in. * * @param modifiedOptions * The options to apply defaults to. */ protected static void applyDefaults(final FileRequestOptions modifiedOptions) { Utility.assertNotNull("modifiedOptions", modifiedOptions); RequestOptions.applyBaseDefaultsInternal(modifiedOptions); if (modifiedOptions.getConcurrentRequestCount() == null) { modifiedOptions.setConcurrentRequestCount(FileConstants.DEFAULT_CONCURRENT_REQUEST_COUNT); } if (modifiedOptions.getUseTransactionalContentMD5() == null) { modifiedOptions.setUseTransactionalContentMD5(false); } if (modifiedOptions.getStoreFileContentMD5() == null) { modifiedOptions.setStoreFileContentMD5(false); } if (modifiedOptions.getDisableContentMD5Validation() == null) { modifiedOptions.setDisableContentMD5Validation(false); } }
/** * Applies defaults to the options passed in. * * @param modifiedOptions * The options to apply defaults to. */ protected static void applyDefaults(final FileRequestOptions modifiedOptions) { Utility.assertNotNull("modifiedOptions", modifiedOptions); RequestOptions.applyBaseDefaultsInternal(modifiedOptions); if (modifiedOptions.getConcurrentRequestCount() == null) { modifiedOptions.setConcurrentRequestCount(FileConstants.DEFAULT_CONCURRENT_REQUEST_COUNT); } if (modifiedOptions.getUseTransactionalContentMD5() == null) { modifiedOptions.setUseTransactionalContentMD5(false); } if (modifiedOptions.getStoreFileContentMD5() == null) { modifiedOptions.setStoreFileContentMD5(false); } if (modifiedOptions.getDisableContentMD5Validation() == null) { modifiedOptions.setDisableContentMD5Validation(false); } }
this.validateFileMd5 = !options.getDisableContentMD5Validation() && !Utility.isNullOrEmpty(this.retrievedContentMD5Value);
this.validateFileMd5 = !options.getDisableContentMD5Validation() && !Utility.isNullOrEmpty(this.retrievedContentMD5Value);
if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5() && Utility.isNullOrEmpty(this.getContentMD5())) { throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5,
if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5() && Utility.isNullOrEmpty(this.getContentMD5())) { throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5,