signature:
public class CloudFile { /** * Downloads the contents of a file to a stream using the specified request options and operation context .
 * @ param outStream
 * An < code > OutputStream < / code > object that represents the target stream .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final void download ( final OutputStream outStream , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation:
if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . downloadToStreamImpl ( null /* fileOffset */
, null /* length */
, outStream , accessCondition , options , opContext ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Downloads the contents of a file to a stream .
 * @ param offset
 * A < code > long < / code > which represents the offset to use as the starting point for the source .
 * @ param length
 * A < code > Long < / code > which represents the number of bytes to read or < code > null < / code > .
 * @ param outStream
 * An < code > { @ link OutputStream } < / code > object that represents the target stream .
 * @ throws StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final void downloadRange ( final long offset , final Long length , final OutputStream outStream ) throws StorageException { } }

implementation:
this . downloadRange ( offset , length , outStream , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Downloads the contents of a file to a stream using the specified request options and operation context .
 * @ param offset
 * A < code > long < / code > which represents the offset to use as the starting point for the source .
 * @ param length
 * A < code > Long < / code > which represents the number of bytes to read or < code > null < / code > .
 * @ param outStream
 * An < code > { @ link OutputStream } < / code > object that represents the target stream .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final void downloadRange ( final long offset , final Long length , final OutputStream outStream , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation: if ( offset < 0 || ( length != null && length <= 0 ) ) { throw new IndexOutOfBoundsException ( ) ; } if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . downloadToStreamImpl ( offset , length , outStream , accessCondition , options , opContext ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Downloads a range of bytes from the file to the given byte buffer .
 * @ param fileOffset
 * A < code > long < / code > which represents the offset within the file to begin downloading .
 * @ param length
 * A < code > Long < / code > which represents the number of bytes to read .
 * @ param buffer
 * A < code > byte < / code > array which represents the buffer to write to .
 * @ param bufferOffset
 * An < code > int < / code > which represents the offset in the byte buffer to begin writing .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } object that specifies any additional options for the request .
 * @ param opContext
 * An { @ link OperationContext } object used to track the execution of the operation .
 * @ throws StorageException
 * an exception representing any error which occurred during the operation . */
@ DoesServiceRequest protected final int downloadRangeInternal ( final long fileOffset , final Long length , final byte [ ] buffer , final int bufferOffset , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation: if ( bufferOffset < 0 || fileOffset < 0 || ( length != null && length <= 0 ) ) { throw new IndexOutOfBoundsException ( ) ; } if ( opContext == null ) { opContext = new OperationContext ( ) ; } options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; WrappedByteArrayOutputStream outputStream = new WrappedByteArrayOutputStream ( buffer , bufferOffset ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . downloadToStreamImpl ( fileOffset , length , outputStream , accessCondition , options , opContext ) , options . getRetryPolicyFactory ( ) , opContext ) ; return outputStream . getPosition ( ) ;


signature:
public class CloudFile { /** * Downloads a range of bytes from the file to the given byte buffer .
 * @ param offset
 * A < code > long < / code > which represents the byte offset to use as the starting point for the source .
 * @ param length
 * A < code > Long < / code > which represents the number of bytes to read or null .
 * @ param buffer
 * A < code > byte < / code > array which represents the buffer to which the file bytes are downloaded .
 * @ param bufferOffset
 * An < code > int < / code > which represents the byte offset to use as the starting point for the target .
 * @ throws StorageException */
@ DoesServiceRequest public final int downloadRangeToByteArray ( final long offset , final Long length , final byte [ ] buffer , final int bufferOffset ) throws StorageException { } }

implementation:
return this . downloadRangeToByteArray ( offset , length , buffer , bufferOffset , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Downloads a range of bytes from the file to the given byte buffer , using the specified request options and
 * operation context .
 * @ param offset
 * A < code > long < / code > which represents the byte offset to use as the starting point for the source .
 * @ param length
 * A < code > Long < / code > which represents the number of bytes to read or < code > null < / code > .
 * @ param buffer
 * A < code > byte < / code > array which represents the buffer to which the file bytes are downloaded .
 * @ param bufferOffset
 * An < code > int < / code > which represents the byte offset to use as the starting point for the target .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final int downloadRangeToByteArray ( final long offset , final Long length , final byte [ ] buffer , final int bufferOffset , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation: Utility . assertNotNull ( "buffer" , buffer ) ; if ( length != null ) { if ( length + bufferOffset > buffer . length ) { throw new IndexOutOfBoundsException ( ) ; } } if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; return this . downloadRangeInternal ( offset , length , buffer , bufferOffset , accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Downloads a range of bytes from the file to the given byte buffer .
 * @ param buffer
 * A < code > byte < / code > array which represents the buffer to which the file bytes are downloaded .
 * @ param bufferOffset
 * An < code > int < / code > which represents the byte offset to use as the starting point for the target .
 * @ throws StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final int downloadToByteArray ( final byte [ ] buffer , final int bufferOffset ) throws StorageException { } }

implementation:
return this . downloadToByteArray ( buffer , bufferOffset , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Downloads a range of bytes from the file to the given byte buffer , using the specified request options and
 * operation context .
 * @ param buffer
 * A < code > byte < / code > array which represents the buffer to which the file bytes are downloaded .
 * @ param bufferOffset
 * A < code > long < / code > which represents the byte offset to use as the starting point for the target .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final int downloadToByteArray ( final byte [ ] buffer , final int bufferOffset , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation: Utility . assertNotNull ( "buffer" , buffer ) ; if ( bufferOffset < 0 ) { throw new IndexOutOfBoundsException ( ) ; } if ( bufferOffset >= buffer . length ) { throw new IndexOutOfBoundsException ( ) ; } if ( opContext == null ) { opContext = new OperationContext ( ) ; } opContext . initialize ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; WrappedByteArrayOutputStream outputStream = new WrappedByteArrayOutputStream ( buffer , bufferOffset ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . downloadToStreamImpl ( null , null , outputStream , accessCondition , options , opContext ) , options . getRetryPolicyFactory ( ) , opContext ) ; return outputStream . getPosition ( ) ;


signature:
public class CloudFile { /** * Downloads a file .
 * @ param path
 * A < code > String < / code > which represents the path to the file that will be created .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws IOException */
public void downloadToFile ( final String path ) throws StorageException , IOException { } }

implementation:
downloadToFile ( path , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Downloads a file .
 * @ param path
 * A < code > String < / code > which represents the path to the file that will be created .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred .
 * @ throws IOException */
public void downloadToFile ( final String path , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException { } }

implementation: OutputStream outputStream = new BufferedOutputStream ( new java . io . FileOutputStream ( path ) ) ; try { this . download ( outputStream , accessCondition , options , opContext ) ; outputStream . close ( ) ; } catch ( StorageException e ) { deleteEmptyFileOnException ( outputStream , path ) ; throw e ; } catch ( IOException e ) { deleteEmptyFileOnException ( outputStream , path ) ; throw e ; }


signature:
public class CloudFile { /** * Helper to delete an empty file in the case of an exception
 * @ param outputStream
 * @ param path
 * @ throws IOException */
private void deleteEmptyFileOnException ( OutputStream outputStream , String path ) { } }

implementation:
try { outputStream . close ( ) ; File fileToDelete = new File ( path ) ; fileToDelete . delete ( ) ; } catch ( Exception e ) { // Best effort delete .
}


signature:
public class CloudFile { /** * Downloads a file to a string using the specified encoding .
 * @ param charsetName
 * A < code > String < / code > which represents the name of the charset to use to encode the content .
 * If null , the platform ' s default encoding is used .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 .
 * @ return A < code > String < / code > which represents the file ' s contents .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws IOException */
public String downloadText ( final String charsetName , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException { } }

implementation: ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; this . download ( baos , accessCondition , options , opContext ) ; return charsetName == null ? baos . toString ( ) : baos . toString ( charsetName ) ;


signature:
public class CloudFile { /** * Returns a collection of file ranges and their starting and ending byte offsets using the specified request
 * options and operation context .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 .
 * @ return An < code > ArrayList < / code > object which represents the set of file ranges and their starting
 * and ending byte offsets .
 * @ throws StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public ArrayList < FileRange > downloadFileRanges ( final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation: if ( opContext == null ) { opContext = new OperationContext ( ) ; } options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; return ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . downloadFileRangesImpl ( accessCondition , options ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Populates a file ' s properties and metadata using the specified request options and operation context .
 * This method populates the file ' s system properties and user - defined metadata . Before reading or modifying
 * a file ' s properties or metadata , call this method or its overload to retrieve the latest values for
 * the file ' s properties and metadata from the Microsoft Azure storage service .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final void downloadAttributes ( final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation: if ( opContext == null ) { opContext = new OperationContext ( ) ; } options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . downloadAttributesImpl ( accessCondition , options ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Returns a shared access signature for the file using the specified group policy identifier and
 * shared access file headers . Note this does not contain the leading " ? " .
 * @ param policy
 * A < code > { @ link SharedAccessFilePolicy } < / code > object that represents the access policy for the shared
 * access signature .
 * @ param headers
 * A < code > { @ link SharedAccessFileHeaders } < / code > object that represents the optional header values to
 * set for a file accessed with this shared access signature .
 * @ param groupPolicyIdentifier
 * A < code > String < / code > that represents the share - level access policy .
 * @ return A < code > String < / code > that represents the shared access signature .
 * @ throws IllegalArgumentException
 * If the credentials are invalid .
 * @ throws InvalidKeyException
 * If the credentials are invalid .
 * @ throws StorageException
 * If a storage service error occurred . */
public String generateSharedAccessSignature ( final SharedAccessFilePolicy policy , final SharedAccessFileHeaders headers , final String groupPolicyIdentifier ) throws InvalidKeyException , StorageException { } }

implementation:
return this . generateSharedAccessSignature ( policy , headers , groupPolicyIdentifier , null /* IP range */
, null /* protocols */
) ;


signature:
public class CloudFile { /** * Returns a shared access signature for the file using the specified group policy identifier and
 * shared access file headers . Note this does not contain the leading " ? " .
 * @ param policy
 * A < code > { @ link SharedAccessFilePolicy } < / code > object that represents the access policy for the shared
 * access signature .
 * @ param headers
 * A < code > { @ link SharedAccessFileHeaders } < / code > object that represents the optional header values to
 * set for a file accessed with this shared access signature .
 * @ param groupPolicyIdentifier
 * A < code > String < / code > that represents the share - level access policy .
 * @ param ipRange
 * A { @ link IPRange } object containing the range of allowed IP addresses .
 * @ param protocols
 * A { @ link SharedAccessProtocols } representing the allowed Internet protocols .
 * @ return A < code > String < / code > that represents the shared access signature .
 * @ throws IllegalArgumentException
 * If the credentials are invalid .
 * @ throws InvalidKeyException
 * If the credentials are invalid .
 * @ throws StorageException
 * If a storage service error occurred . */
public String generateSharedAccessSignature ( final SharedAccessFilePolicy policy , final SharedAccessFileHeaders headers , final String groupPolicyIdentifier , final IPRange ipRange , final SharedAccessProtocols protocols ) throws InvalidKeyException , StorageException { } }

implementation: if ( ! StorageCredentialsHelper . canCredentialsSignRequest ( this . fileServiceClient . getCredentials ( ) ) ) { throw new IllegalArgumentException ( SR . CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY ) ; } final String signature = SharedAccessSignatureHelper . generateSharedAccessSignatureHashForBlobAndFile ( policy , headers , groupPolicyIdentifier , this . getCanonicalName ( ) , ipRange , protocols , this . fileServiceClient ) ; final UriQueryBuilder builder = SharedAccessSignatureHelper . generateSharedAccessSignatureForBlobAndFile ( policy , headers , groupPolicyIdentifier , "f" , ipRange , protocols , signature ) ; return builder . toString ( ) ;


signature:
public class CloudFile { /** * Returns the canonical name of the file in the format of
 * < i > / & lt ; service - name & gt ; / & lt ; account - name & gt ; / & lt ; share - name & gt ; / & lt ; file - name & gt ; < / i > .
 * This format is used for Shared Access operations .
 * @ return The canonical name in the format of < i > / & lt ; service - name & gt ; / & lt ; account - name & gt ;
 * / & lt ; share - name & gt ; / & lt ; file - name & gt ; < / i > . */
String getCanonicalName ( ) { } }

implementation: StringBuilder canonicalName = new StringBuilder ( "/" ) ; canonicalName . append ( SR . FILE ) ; String rawPath = this . getUri ( ) . getRawPath ( ) ; if ( this . fileServiceClient . isUsePathStyleUris ( ) ) { canonicalName . append ( rawPath ) ; } else { canonicalName . append ( PathUtility . getCanonicalPathFromCredentials ( this . getServiceClient ( ) . getCredentials ( ) , rawPath ) ) ; } return canonicalName . toString ( ) ;


signature:
public class CloudFile { /** * Opens a file input stream to download the file using the specified request options and
 * operation context .
 * Use { @ link # setStreamMinimumReadSizeInBytes ( int ) } to configure the read size .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 .
 * @ return An < code > InputStream < / code > object that represents the stream to use for reading from the file .
 * @ throws StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest public final FileInputStream openRead ( final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException { } }

implementation:
if ( opContext == null ) { opContext = new OperationContext ( ) ; } options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient , false /* setStartTime */
) ; return new FileInputStream ( this , accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Opens an output stream object to write data to the file . The file must already exist and any existing data may
 * be overwritten .
 * @ return A { @ link FileOutputStream } object used to write data to the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public FileOutputStream openWriteExisting ( ) throws StorageException , URISyntaxException { } }

implementation:
return this . openOutputStreamInternal ( null /* length */
, null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Opens an output stream object to write data to the file , using specified request options and
 * operation context . The file must already exist and any existing data may be overwritten .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 .
 * @ return A { @ link FileOutputStream } object used to write data to the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public FileOutputStream openWriteExisting ( AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , URISyntaxException { } }

implementation:
return this . openOutputStreamInternal ( null /* length */
, accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Opens an output stream object to write data to the file . The file does not yet exist and will
 * be created with the length specified . If the file already exists on the service , it will be overwritten .
 * To avoid overwriting and instead throw an error , please use the
 * { @ link # openWriteNew ( long , AccessCondition , FileRequestOptions , OperationContext ) } overload with the appropriate
 * { @ link AccessCondition } .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the stream to create .
 * @ return A { @ link FileOutputStream } object used to write data to the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public FileOutputStream openWriteNew ( final long length ) throws StorageException , URISyntaxException { } }

implementation:
return this . openOutputStreamInternal ( length , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Opens an output stream object to write data to the file , using the specified lease ID , request options and
 * operation context . The file does not need to yet exist and will be created with the length specified . If the file
 * already exists on the service , it will be overwritten .
 * To avoid overwriting and instead throw an error , please pass in an { @ link AccessCondition } generated using
 * { @ link AccessCondition # generateIfNotExistsCondition ( ) } .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the stream to create .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 .
 * @ return A { @ link FileOutputStream } object used to write data to the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public FileOutputStream openWriteNew ( final long length , AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , URISyntaxException { } }

implementation: return openOutputStreamInternal ( length , accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Opens an output stream object to write data to the file , using the specified lease ID , request options and
 * operation context . If the length is specified , a new file will be created with the length specified .
 * Otherwise , the file must already exist and a stream of its current length will be opened .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the stream to create . This value must be
 * null if the file already exists .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 .
 * @ return A { @ link FileOutputStream } object used to write data to the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
private FileOutputStream openOutputStreamInternal ( Long length , AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , URISyntaxException { } }

implementation:
if ( opContext == null ) { opContext = new OperationContext ( ) ; } this . getShare ( ) . assertNoSnapshot ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient , false /* setStartTime */
) ; if ( length != null ) { this . create ( length , accessCondition , options , opContext ) ; } else { if ( options . getStoreFileContentMD5 ( ) ) { throw new IllegalArgumentException ( SR . FILE_MD5_NOT_POSSIBLE ) ; } this . downloadAttributes ( accessCondition , options , opContext ) ; length = this . getProperties ( ) . getLength ( ) ; } if ( accessCondition != null ) { accessCondition = AccessCondition . generateLeaseCondition ( accessCondition . getLeaseID ( ) ) ; } return new FileOutputStream ( this , length , accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Uploads a file from data in a byte array . If the file already exists on the service , it will be overwritten .
 * @ param buffer
 * A < code > byte < / code > array which represents the data to write to the file .
 * @ param offset
 * A < code > int < / code > which represents the offset of the byte array from which to start the data upload .
 * @ param length
 * An < code > int < / code > which represents the number of bytes to upload from the input buffer .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws IOException
 * @ throws URISyntaxException */
public void uploadFromByteArray ( final byte [ ] buffer , final int offset , final int length ) throws StorageException , IOException , URISyntaxException { } }

implementation:
uploadFromByteArray ( buffer , offset , length , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Uploads a file from data in a byte array . If the file already exists on the service , it will be overwritten .
 * @ param buffer
 * A < code > byte < / code > array which represents the data to write to the file .
 * @ param offset
 * A < code > int < / code > which represents the offset of the byte array from which to start the data upload .
 * @ param length
 * An < code > int < / code > which represents the number of bytes to upload from the input buffer .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred .
 * @ throws IOException
 * @ throws URISyntaxException */
public void uploadFromByteArray ( final byte [ ] buffer , final int offset , final int length , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException , URISyntaxException { } }

implementation: ByteArrayInputStream inputStream = new ByteArrayInputStream ( buffer , offset , length ) ; this . upload ( inputStream , length , accessCondition , options , opContext ) ; inputStream . close ( ) ;


signature:
public class CloudFile { /** * Uploads a local file . If the file already exists on the service , it will be overwritten .
 * @ param path
 * A < code > String < / code > which represents the path to the file to be uploaded .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws IOException
 * @ throws URISyntaxException */
public void uploadFromFile ( final String path ) throws StorageException , IOException , URISyntaxException { } }

implementation:
uploadFromFile ( path , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Uploads a file from a local file . If the file already exists on the service , it will be overwritten .
 * @ param path
 * A < code > String < / code > which represents the path to the file to be uploaded .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred .
 * @ throws IOException
 * @ throws URISyntaxException */
public void uploadFromFile ( final String path , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException , URISyntaxException { } }

implementation: File file = new File ( path ) ; long fileLength = file . length ( ) ; InputStream inputStream = new BufferedInputStream ( new java . io . FileInputStream ( file ) ) ; this . upload ( inputStream , fileLength , accessCondition , options , opContext ) ; inputStream . close ( ) ;


signature:
public class CloudFile { /** * Uploads a file from a string using the platform ' s default encoding . If the file already exists on the service , it
 * will be overwritten .
 * @ param content
 * A < code > String < / code > which represents the content that will be uploaded to the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws IOException
 * @ throws URISyntaxException */
public void uploadText ( final String content ) throws StorageException , IOException , URISyntaxException { } }

implementation:
this . uploadText ( content , null /* charsetName */
, null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Uploads a file from a string using the specified encoding . If the file already exists on the service , it will be
 * overwritten .
 * @ param content
 * A < code > String < / code > which represents the content that will be uploaded to the file .
 * @ param charsetName
 * A < code > String < / code > which represents the name of the charset to use to encode the content .
 * If null , the platform ' s default encoding is used .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred .
 * @ throws IOException
 * @ throws URISyntaxException */
public void uploadText ( final String content , final String charsetName , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException , URISyntaxException { } }

implementation: byte [ ] bytes = ( charsetName == null ) ? content . getBytes ( ) : content . getBytes ( charsetName ) ; this . uploadFromByteArray ( bytes , 0 , bytes . length , accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Uploads a range to a file .
 * @ param sourceStream
 * An { @ link InputStream } object which represents the input stream to write to the file .
 * @ param offset
 * A < code > long < / code > which represents the offset , in number of bytes , at which to begin writing the
 * data .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the data to write .
 * @ throws IOException
 * If an I / O exception occurred .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public void uploadRange ( final InputStream sourceStream , final long offset , final long length ) throws StorageException , IOException , URISyntaxException { } }

implementation:
this . uploadRange ( sourceStream , offset , length , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Uploads a range to a file using the specified lease ID , request options , and operation context .
 * @ param sourceStream
 * An { @ link InputStream } object which represents the input stream to write to the file .
 * @ param offset
 * A < code > long < / code > which represents the offset , in number of bytes , at which to begin writing the
 * data .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the data to write .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 IOException
 * If an I / O exception occurred .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public void uploadRange ( final InputStream sourceStream , final long offset , final long length , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException , URISyntaxException { } }

implementation:
if ( opContext == null ) { opContext = new OperationContext ( ) ; } this . getShare ( ) . assertNoSnapshot ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; final FileRange range = new FileRange ( offset , offset + length - 1 ) ; final byte [ ] data = new byte [ ( int ) length ] ; String md5 = null ; int count = 0 ; int total = 0 ; while ( total < length ) { count = sourceStream . read ( data , total , ( int ) Math . min ( length - total , Integer . MAX_VALUE ) ) ; total += count ; } if ( options . getUseTransactionalContentMD5 ( ) ) { try { final MessageDigest digest = MessageDigest . getInstance ( "MD5" ) ; digest . update ( data , 0 , data . length ) ; md5 = Base64 . encode ( digest . digest ( ) ) ; } catch ( final NoSuchAlgorithmException e ) { // This wont happen , throw fatal .
throw Utility . generateNewUnexpectedStorageException ( e ) ; } } this . putRangeInternal ( range , FileRangeOperationType . UPDATE , data , length , md5 , accessCondition , options , opContext ) ;


signature:
public class CloudFile { /** * Used for both uploadRange and clearRange .
 * @ param range
 * A { @ link FileRange } object that specifies the file range .
 * @ param operationType
 * A { @ link FileRangeOperationType } enumeration value that specifies the operation type .
 * @ param data
 * A < code > byte < / code > array which represents the data to write .
 * @ param length
 * A < code > long < / code > which represents the number of bytes to write .
 * @ param md5
 * A < code > String < / code > which represents the MD5 hash for the data .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 StorageException
 * If a storage service error occurred . */
@ DoesServiceRequest private void putRangeInternal ( final FileRange range , final FileRangeOperationType operationType , final byte [ ] data , final long length , final String md5 , final AccessCondition accessCondition , final FileRequestOptions options , final OperationContext opContext ) throws StorageException { } }

implementation: ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , putRangeImpl ( range , operationType , data , length , md5 , accessCondition , options , opContext ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Uploads the file ' s metadata to the storage service using the access condition , request options , and operation
 * context .
 * Use { @ link CloudFile # downloadAttributes } to retrieve the latest values for the file ' s properties and metadata
 * from the Microsoft Azure storage service .
 * @ param accessCondition
 * An { @ link AccessCondition } object that represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ param opContext
 * An { @ link OperationContext } object that 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 StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public final void uploadMetadata ( final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , URISyntaxException { } }

implementation: if ( opContext == null ) { opContext = new OperationContext ( ) ; } this . getShare ( ) . assertNoSnapshot ( ) ; opContext . initialize ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . uploadMetadataImpl ( accessCondition , options ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Resizes the file to the specified size .
 * @ param size
 * A < code > long < / code > which represents the size of the file , in bytes .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
public void resize ( long size , AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , URISyntaxException { } }

implementation: if ( opContext == null ) { opContext = new OperationContext ( ) ; } this . getShare ( ) . assertNoSnapshot ( ) ; opContext . initialize ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; ExecutionEngine . executeWithRetry ( this . fileServiceClient , this , this . resizeImpl ( size , accessCondition , options ) , options . getRetryPolicyFactory ( ) , opContext ) ;


signature:
public class CloudFile { /** * Uploads the source stream data to the file . If the file already exists on the service , it will be overwritten .
 * @ param sourceStream
 * An { @ link InputStream } object to read from .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the stream data . Must be non zero .
 * @ throws IOException
 * If an I / O exception occurred .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public void upload ( final InputStream sourceStream , final long length ) throws StorageException , IOException , URISyntaxException { } }

implementation:
this . upload ( sourceStream , length , null /* accessCondition */
, null /* options */
, null /* opContext */
) ;


signature:
public class CloudFile { /** * Uploads the source stream data to the file using the specified access condition , request options , and operation
 * context . If the file already exists on the service , it will be overwritten .
 * @ param sourceStream
 * An { @ link InputStream } object to read from .
 * @ param length
 * A < code > long < / code > which represents the length , in bytes , of the stream data . This must be greater than
 * or equal to zero .
 * @ param accessCondition
 * An { @ link AccessCondition } object which represents the access conditions for the file .
 * @ param options
 * A { @ link FileRequestOptions } 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 CloudFileClient } ) .
 * @ 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 IOException
 * If an I / O exception occurred .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
@ DoesServiceRequest public void upload ( final InputStream sourceStream , final long length , final AccessCondition accessCondition , FileRequestOptions options , OperationContext opContext ) throws StorageException , IOException , URISyntaxException { } }

implementation:
if ( opContext == null ) { opContext = new OperationContext ( ) ; } this . getShare ( ) . assertNoSnapshot ( ) ; options = FileRequestOptions . populateAndApplyDefaults ( options , this . fileServiceClient ) ; if ( length < 0 ) { throw new IllegalArgumentException ( SR . INVALID_FILE_LENGTH ) ; } if ( sourceStream . markSupported ( ) ) { // Mark sourceStream for current position .
sourceStream . mark ( Constants . MAX_MARK_LENGTH ) ; } final FileOutputStream streamRef = this . openWriteNew ( length , accessCondition , options , opContext ) ; try { streamRef . write ( sourceStream , length ) ; } finally { streamRef . close ( ) ; }


signature:
public class CloudFile { /** * Retrieves the parent name for a file URI .
 * @ param resourceAddress
 * A { @ link StorageUri } object which represents the resource URI .
 * @ param delimiter
 * A < code > String < / code > which specifies the directory delimiter to use .
 * @ param usePathStyleUris
 * A < code > Boolean < / code > which specifies whether path style URIs are used .
 * @ param share
 * A { @ link CloudFileShare } object which represents the file share .
 * @ return A < code > String < / code > which represents the parent address for a file URI .
 * @ throws URISyntaxException */
protected static String getParentNameFromURI ( final StorageUri resourceAddress , final CloudFileShare share ) throws URISyntaxException { } }

implementation:
Utility . assertNotNull ( "resourceAddress" , resourceAddress ) ; Utility . assertNotNull ( "share" , share ) ; String delimiter = "/" ; String shareName = share . getName ( ) + delimiter ; String relativeURIString = Utility . safeRelativize ( share . getStorageUri ( ) . getPrimaryUri ( ) , resourceAddress . getPrimaryUri ( ) ) ; if ( relativeURIString . endsWith ( delimiter ) ) { relativeURIString = relativeURIString . substring ( 0 , relativeURIString . length ( ) - delimiter . length ( ) ) ; } String parentName ; if ( Utility . isNullOrEmpty ( relativeURIString ) ) { // Case 1 / < ShareName > [ Delimiter ] * ? = > / < ShareName >
// Parent of share is share itself
parentName = null ; } else { final int lastDelimiterDex = relativeURIString . lastIndexOf ( delimiter ) ; if ( lastDelimiterDex < 0 ) { // Case 2 / < Share > / < Directory >
// Parent of a Directory is Share
parentName = "" ; } else { // Case 3 / < Share > / < Directory > / [ < subDirectory > / ] * < FileName >
// Parent of CloudFile is CloudFileDirectory
parentName = relativeURIString . substring ( 0 , lastDelimiterDex ) ; if ( parentName != null && parentName . equals ( shareName ) ) { parentName = "" ; } } } return parentName ;


signature:
public class CloudFile { /** * Verifies the passed in URI . Then parses it and uses its components to populate this resource ' s properties .
 * @ param completeUri
 * A { @ link StorageUri } object which represents the complete URI .
 * @ param credentials
 * A { @ link StorageCredentials } object used to authenticate access .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException */
private void parseQueryAndVerify ( final StorageUri completeUri , final StorageCredentials credentials ) throws StorageException , URISyntaxException { } }

implementation: Utility . assertNotNull ( "completeUri" , completeUri ) ; if ( ! completeUri . isAbsolute ( ) ) { throw new IllegalArgumentException ( String . format ( SR . RELATIVE_ADDRESS_NOT_PERMITTED , completeUri . toString ( ) ) ) ; } this . storageUri = PathUtility . stripURIQueryAndFragment ( completeUri ) ; final StorageCredentialsSharedAccessSignature parsedCredentials = SharedAccessSignatureHelper . parseQuery ( completeUri ) ; if ( credentials != null && parsedCredentials != null ) { throw new IllegalArgumentException ( SR . MULTIPLE_CREDENTIALS_PROVIDED ) ; } try { final boolean usePathStyleUris = Utility . determinePathStyleFromUri ( this . storageUri . getPrimaryUri ( ) ) ; this . fileServiceClient = new CloudFileClient ( PathUtility . getServiceClientBaseAddress ( this . getStorageUri ( ) , usePathStyleUris ) , credentials != null ? credentials : parsedCredentials ) ; this . name = PathUtility . getFileNameFromURI ( this . storageUri . getPrimaryUri ( ) , usePathStyleUris ) ; } catch ( final URISyntaxException e ) { throw Utility . generateNewUnexpectedStorageException ( e ) ; } final HashMap < String , String [ ] > queryParameters = PathUtility . parseQueryString ( completeUri . getQuery ( ) ) ; final String [ ] snapshotIDs = queryParameters . get ( Constants . QueryConstants . SHARE_SNAPSHOT ) ; if ( snapshotIDs != null && snapshotIDs . length > 0 ) { this . getShare ( ) . snapshotID = snapshotIDs [ 0 ] ; }


signature:
public class CloudFile { /** * Returns the file ' s share .
 * @ return A { @ link CloudFileShare } object that represents the share of the file .
 * @ throws StorageException
 * If a storage service error occurred .
 * @ throws URISyntaxException
 * If the resource URI is invalid . */
@ Override public final CloudFileShare getShare ( ) throws StorageException , URISyntaxException { } }

implementation: if ( this . share == null ) { final StorageUri shareUri = PathUtility . getShareURI ( this . getStorageUri ( ) , this . fileServiceClient . isUsePathStyleUris ( ) ) ; this . share = new CloudFileShare ( shareUri , this . fileServiceClient . getCredentials ( ) ) ; } return this . share ;


signature:
public class CloudFile { /** * Sets the number of bytes to buffer when writing to a { @ link FileOutputStream } .
 * @ param streamWriteSizeInBytes
 * An < code > int < / code > which represents the number of bytes to buffer while using a
 * { @ link FileOutputStream } object , ranging from 512 bytes to 4 MB , inclusive .
 * @ throws IllegalArgumentException
 * If < code > streamWriteSizeInBytes < / code > is less than 512 bytes or greater than 4 MB . */
public void setStreamWriteSizeInBytes ( final int streamWriteSizeInBytes ) { } }

implementation: if ( streamWriteSizeInBytes > Constants . MAX_BLOCK_SIZE || streamWriteSizeInBytes < Constants . PAGE_SIZE ) { throw new IllegalArgumentException ( "StreamWriteSizeInBytes" ) ; } this . streamWriteSizeInBytes = streamWriteSizeInBytes ;


signature:
public class PathUtility { /** * Adds a queryString to an URI .
 * @ param resourceURI
 * the URI of the resource
 * @ param fieldCollection
 * the key / values collection to append .
 * @ return an appended URI .
 * @ throws URISyntaxException
 * if the resulting URI is invalid .
 * @ throws StorageException */
public static URI addToSingleUriQuery ( final URI resourceURI , final HashMap < String , String [ ] > fieldCollection ) throws URISyntaxException , StorageException { } }

implementation:
if ( resourceURI == null ) { return null ; } final UriQueryBuilder outUri = new UriQueryBuilder ( ) ; // Generate new queryString
for ( final Entry < String , String [ ] > entry : fieldCollection . entrySet ( ) ) { for ( final String val : entry . getValue ( ) ) { outUri . add ( entry . getKey ( ) , val ) ; } } return outUri . addToURI ( resourceURI ) ;


signature:
public class PathUtility { /** * Adds a queryString to an URI .
 * @ param resourceURI
 * the URI of the resource
 * @ param queryString
 * the query string to add
 * @ return an appended URI .
 * @ throws URISyntaxException
 * if the resulting URI is invalid .
 * @ throws StorageException */
public static StorageUri addToQuery ( final StorageUri resourceURI , final String queryString ) throws URISyntaxException , StorageException { } }

implementation: return new StorageUri ( addToSingleUriQuery ( resourceURI . getPrimaryUri ( ) , parseQueryString ( queryString ) ) , addToSingleUriQuery ( resourceURI . getSecondaryUri ( ) , parseQueryString ( queryString ) ) ) ;


signature:
public class PathUtility { /** * Adds a queryString to an URI .
 * @ param resourceURI
 * the URI of the resource
 * @ param queryString
 * the query string to add
 * @ return an appended URI .
 * @ throws URISyntaxException
 * if the resulting URI is invalid .
 * @ throws StorageException */
public static URI addToQuery ( final URI resourceURI , final String queryString ) throws URISyntaxException , StorageException { } }

implementation: return addToSingleUriQuery ( resourceURI , parseQueryString ( queryString ) ) ;


signature:
public class PathUtility { /** * Appends a path to a list of URIs correctly using " / " as separator .
 * @ param uriList
 * The base Uri .
 * @ param relativeOrAbslouteUri
 * The relative or absloute URI .
 * @ return The appended Uri .
 * @ throws URISyntaxException */
public static StorageUri appendPathToUri ( final StorageUri uriList , final String relativeOrAbsoluteUri ) throws URISyntaxException { } }

implementation: return appendPathToUri ( uriList , relativeOrAbsoluteUri , "/" ) ;


signature:
public class PathUtility { /** * Appends a path to a list of URIs correctly using " / " as separator .
 * @ param uriList
 * The base Uri .
 * @ param relativeOrAbslouteUri
 * The relative or absloute URI .
 * @ return The appended Uri .
 * @ throws URISyntaxException */
public static StorageUri appendPathToUri ( final StorageUri uriList , final String relativeOrAbsoluteUri , final String separator ) throws URISyntaxException { } }

implementation: return new StorageUri ( appendPathToSingleUri ( uriList . getPrimaryUri ( ) , relativeOrAbsoluteUri , separator ) , appendPathToSingleUri ( uriList . getSecondaryUri ( ) , relativeOrAbsoluteUri , separator ) ) ;


signature:
public class PathUtility { /** * Appends a path to a URI correctly using " / " as separator .
 * @ param uriList
 * The base Uri .
 * @ param relativeOrAbslouteUri
 * The relative or absloute URI .
 * @ return The appended Uri .
 * @ throws URISyntaxException */
public static URI appendPathToSingleUri ( final URI uri , final String relativeOrAbsoluteUri ) throws URISyntaxException { } }

implementation: return appendPathToSingleUri ( uri , relativeOrAbsoluteUri , "/" ) ;


signature:
public class PathUtility { /** * Appends a path to a URI correctly using the given separator .
 * @ param uri
 * The base Uri .
 * @ param relativeUri
 * The relative URI .
 * @ param separator
 * the separator to use .
 * @ return The appended Uri .
 * @ throws URISyntaxException
 * a valid Uri cannot be constructed */
public static URI appendPathToSingleUri ( final URI uri , final String relativeUri , final String separator ) throws URISyntaxException { } }

implementation: if ( uri == null ) { return null ; } if ( relativeUri == null || relativeUri . isEmpty ( ) ) { return uri ; } if ( uri . getPath ( ) . length ( ) == 0 && relativeUri . startsWith ( separator ) ) { return new URI ( uri . getScheme ( ) , uri . getAuthority ( ) , relativeUri , uri . getRawQuery ( ) , uri . getRawFragment ( ) ) ; } final StringBuilder pathString = new StringBuilder ( uri . getPath ( ) ) ; if ( uri . getPath ( ) . endsWith ( separator ) ) { pathString . append ( relativeUri ) ; } else { pathString . append ( separator ) ; pathString . append ( relativeUri ) ; } return new URI ( uri . getScheme ( ) , uri . getAuthority ( ) , pathString . toString ( ) , uri . getQuery ( ) , uri . getFragment ( ) ) ;


signature:
public class PathUtility { /** * Gets the blob name from the URI .
 * @ param inURI
 * the resource address
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return the blobs name
 * @ throws URISyntaxException */
public static String getBlobNameFromURI ( final URI inURI , final boolean usePathStyleUris ) throws URISyntaxException { } }

implementation: return Utility . safeRelativize ( new URI ( getContainerURI ( new StorageUri ( inURI ) , usePathStyleUris ) . getPrimaryUri ( ) . toString ( ) . concat ( "/" ) ) , inURI ) ;


signature:
public class PathUtility { /** * Gets the canonical path for an object from the credentials .
 * @ param credentials
 * the credentials to use .
 * @ param absolutePath
 * the Absolute path of the object .
 * @ return the canonical path for an object from the credentials */
public static String getCanonicalPathFromCredentials ( final StorageCredentials credentials , final String absolutePath ) { } }

implementation: final String account = credentials . getAccountName ( ) ; if ( account == null ) { final String errorMessage = SR . CANNOT_CREATE_SAS_FOR_GIVEN_CREDENTIALS ; throw new IllegalArgumentException ( errorMessage ) ; } final StringBuilder builder = new StringBuilder ( "/" ) ; builder . append ( account ) ; builder . append ( absolutePath ) ; return builder . toString ( ) ;


signature:
public class PathUtility { /** * Get the container name from address from the URI .
 * @ param resourceAddress
 * The container Uri .
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return container name from address from the URI .
 * @ throws IllegalArgumentException */
public static String getContainerNameFromUri ( final URI resourceAddress , final boolean usePathStyleUris ) { } }

implementation: return getResourceNameFromUri ( resourceAddress , usePathStyleUris , String . format ( "Invalid blob address '%s', missing container information" , resourceAddress ) ) ;


signature:
public class PathUtility { /** * Gets the file name from the URI .
 * @ param resourceAddress
 * the file URI
 * @ param usePathStyleUris
 * a value indicating if the address is a path style URI
 * @ return the file ' s name */
public static String getFileNameFromURI ( final URI resourceAddress , final boolean usePathStyleUris ) { } }

implementation:
// generate an array of the different levels of the path
final String [ ] pathSegments = resourceAddress . getRawPath ( ) . split ( "/" ) ; // usePathStyleUris ? baseuri / accountname / sharename / objectname : accountname . baseuri / sharename / objectname
final int shareIndex = usePathStyleUris ? 2 : 1 ; if ( pathSegments . length - 1 <= shareIndex ) { // legal file addresses cannot end with or before the sharename
throw new IllegalArgumentException ( String . format ( "Invalid file address '%s'." , resourceAddress ) ) ; } else { // in a legal file address the lowest level is the filename
return pathSegments [ pathSegments . length - 1 ] ; }


signature:
public class PathUtility { /** * Get the share name from address from the URI .
 * @ param resourceAddress
 * The share Uri .
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return share name from address from the URI .
 * @ throws IllegalArgumentException */
public static String getShareNameFromUri ( final URI resourceAddress , final boolean usePathStyleUris ) { } }

implementation: return getResourceNameFromUri ( resourceAddress , usePathStyleUris , String . format ( "Invalid file address '%s', missing share information" , resourceAddress ) ) ;


signature:
public class PathUtility { /** * Get the table name from address from the URI .
 * @ param resourceAddress
 * The table Uri .
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return table name from address from the URI .
 * @ throws IllegalArgumentException */
public static String getTableNameFromUri ( final URI resourceAddress , final boolean usePathStyleUris ) { } }

implementation: return getResourceNameFromUri ( resourceAddress , usePathStyleUris , String . format ( "Invalid table address '%s', missing table information" , resourceAddress ) ) ;


signature:
public class PathUtility { /** * Get the container , queue or table name from address from the URI .
 * @ param resourceAddress
 * The queue Uri .
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return container name from address from the URI .
 * @ throws IllegalArgumentException */
private static String getResourceNameFromUri ( final URI resourceAddress , final boolean usePathStyleUris , final String error ) { } }

implementation: Utility . assertNotNull ( "resourceAddress" , resourceAddress ) ; final String [ ] pathSegments = resourceAddress . getRawPath ( ) . split ( "/" ) ; final int expectedPartsLength = usePathStyleUris ? 3 : 2 ; if ( pathSegments . length < expectedPartsLength ) { throw new IllegalArgumentException ( error ) ; } final String resourceName = usePathStyleUris ? pathSegments [ 2 ] : pathSegments [ 1 ] ; return Utility . trimEnd ( resourceName , '/' ) ;


signature:
public class PathUtility { /** * Gets the container URI from a blob address
 * @ param blobAddress
 * the blob address
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return the container URI from a blob address
 * @ throws URISyntaxException */
public static StorageUri getContainerURI ( final StorageUri blobAddress , final boolean usePathStyleUris ) throws URISyntaxException { } }

implementation: final String containerName = getContainerNameFromUri ( blobAddress . getPrimaryUri ( ) , usePathStyleUris ) ; final StorageUri containerUri = appendPathToUri ( getServiceClientBaseAddress ( blobAddress , usePathStyleUris ) , containerName ) ; return containerUri ;


signature:
public class PathUtility { /** * Gets the share URI from a file address
 * @ param fileAddress
 * the file address
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return the share URI from a file address
 * @ throws URISyntaxException */
public static StorageUri getShareURI ( final StorageUri fileAddress , final boolean usePathStyleUris ) throws URISyntaxException { } }

implementation: final String shareName = getShareNameFromUri ( fileAddress . getPrimaryUri ( ) , usePathStyleUris ) ; final StorageUri shareUri = appendPathToUri ( getServiceClientBaseAddress ( fileAddress , usePathStyleUris ) , shareName ) ; return shareUri ;


signature:
public class PathUtility { /** * Get the service client address from a complete Uri .
 * @ param address
 * Complete address of the resource .
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return the service client address from a complete Uri .
 * @ throws URISyntaxException */
public static String getServiceClientBaseAddress ( final URI address , final boolean usePathStyleUris ) throws URISyntaxException { } }

implementation: if ( address == null ) { return null ; } if ( usePathStyleUris ) { final String [ ] pathSegments = address . getRawPath ( ) . split ( "/" ) ; if ( pathSegments . length < 2 ) { final String error = String . format ( SR . PATH_STYLE_URI_MISSING_ACCOUNT_INFORMATION ) ; throw new IllegalArgumentException ( error ) ; } final StringBuilder completeAddress = new StringBuilder ( new URI ( address . getScheme ( ) , address . getAuthority ( ) , null , null , null ) . toString ( ) ) ; completeAddress . append ( "/" ) ; completeAddress . append ( Utility . trimEnd ( pathSegments [ 1 ] , '/' ) ) ; return completeAddress . toString ( ) ; } else { return new URI ( address . getScheme ( ) , address . getAuthority ( ) , null , null , null ) . toString ( ) ; }


signature:
public class PathUtility { /** * Get the service client address from a complete Uri .
 * @ param address
 * Complete address of the resource .
 * @ param usePathStyleUris
 * a value indicating if the address is a path style uri .
 * @ return the service client address from a complete Uri .
 * @ throws URISyntaxException */
public static StorageUri getServiceClientBaseAddress ( final StorageUri addressUri , final boolean usePathStyleUris ) throws URISyntaxException { } }

implementation: return new StorageUri ( new URI ( getServiceClientBaseAddress ( addressUri . getPrimaryUri ( ) , usePathStyleUris ) ) , addressUri . getSecondaryUri ( ) != null ? new URI ( getServiceClientBaseAddress ( addressUri . getSecondaryUri ( ) , usePathStyleUris ) ) : null ) ;


signature:
public class PathUtility { /** * Parses a query string into a one to many hashmap .
 * @ param parseString
 * the string to parse
 * @ return a HashMap < String , String [ ] > of the key values .
 * @ throws StorageException */
public static HashMap < String , String [ ] > parseQueryString ( String parseString ) throws StorageException { } }

implementation:
final HashMap < String , String [ ] > retVals = new HashMap < String , String [ ] > ( ) ; if ( Utility . isNullOrEmpty ( parseString ) ) { return retVals ; } // 1 . Remove ? if present
final int queryDex = parseString . indexOf ( "?" ) ; if ( queryDex >= 0 && parseString . length ( ) > 0 ) { parseString = parseString . substring ( queryDex + 1 ) ; } // 2 . split name value pairs by splitting on the ' c & ' character
final String [ ] valuePairs = parseString . contains ( "&" ) ? parseString . split ( "&" ) : parseString . split ( ";" ) ; // 3 . for each field value pair parse into appropriate map entries
for ( int m = 0 ; m < valuePairs . length ; m ++ ) { final int equalDex = valuePairs [ m ] . indexOf ( "=" ) ; if ( equalDex < 0 || equalDex == valuePairs [ m ] . length ( ) - 1 ) { continue ; } String key = valuePairs [ m ] . substring ( 0 , equalDex ) ; String value = valuePairs [ m ] . substring ( equalDex + 1 ) ; key = Utility . safeDecode ( key ) ; value = Utility . safeDecode ( value ) ; // 3.1 add to map
String [ ] values = retVals . get ( key ) ; if ( values == null ) { values = new String [ ] { value } ; if ( ! value . equals ( Constants . EMPTY_STRING ) ) { retVals . put ( key , values ) ; } } else if ( ! value . equals ( Constants . EMPTY_STRING ) ) { final String [ ] newValues = new String [ values . length + 1 ] ; for ( int j = 0 ; j < values . length ; j ++ ) { newValues [ j ] = values [ j ] ; } newValues [ newValues . length ] = value ; } } return retVals ;


signature:
public class PathUtility { /** * Strips the Query and Fragment from the uri .
 * @ param inUri
 * the uri to alter
 * @ return the stripped uri .
 * @ throws StorageException */
public static URI stripSingleURIQueryAndFragment ( final URI inUri ) throws StorageException { } }

implementation: if ( inUri == null ) { return null ; } try { return new URI ( inUri . getScheme ( ) , inUri . getAuthority ( ) , inUri . getPath ( ) , null , null ) ; } catch ( final URISyntaxException e ) { throw Utility . generateNewUnexpectedStorageException ( e ) ; }


signature:
public class PathUtility { /** * Strips the Query and Fragment from the uri .
 * @ param inUri
 * the uri to alter
 * @ return the stripped uri .
 * @ throws StorageException */
public static StorageUri stripURIQueryAndFragment ( final StorageUri inUri ) throws StorageException { } }

implementation: return new StorageUri ( stripSingleURIQueryAndFragment ( inUri . getPrimaryUri ( ) ) , stripSingleURIQueryAndFragment ( inUri . getSecondaryUri ( ) ) ) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature for a { @ link CloudStorageAccount } .
 * @ param policy
 * The shared access policy to hash .
 * @ param ipRange
 * An optional range of IP addresses .
 * @ param protocols
 * An optional restriction of allowed protocols .
 * @ param signature
 * The signature to use .
 * @ return The finished query builder
 * @ throws InvalidKeyException
 * @ throws StorageException */
public static UriQueryBuilder generateSharedAccessSignatureForAccount ( final SharedAccessAccountPolicy policy , final String signature ) throws StorageException { } }

implementation: Utility . assertNotNull ( "policy" , policy ) ; Utility . assertNotNull ( "signature" , signature ) ; String permissions = null ; Date startTime = null ; Date expiryTime = null ; IPRange ipRange = null ; SharedAccessProtocols protocols = null ; String services = null ; String resourceTypes = null ; if ( policy != null ) { permissions = policy . permissionsToString ( ) ; startTime = policy . getSharedAccessStartTime ( ) ; expiryTime = policy . getSharedAccessExpiryTime ( ) ; ipRange = policy . getRange ( ) ; protocols = policy . getProtocols ( ) ; services = policy . servicesToString ( ) ; resourceTypes = policy . resourceTypesToString ( ) ; } final UriQueryBuilder builder = new UriQueryBuilder ( ) ; builder . add ( Constants . QueryConstants . SIGNED_VERSION , Constants . HeaderConstants . TARGET_STORAGE_VERSION ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_SERVICE , services ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_RESOURCE_TYPE , resourceTypes ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_PERMISSIONS , permissions ) ; final String startString = Utility . getUTCTimeOrEmpty ( startTime ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_START , startString ) ; final String stopString = Utility . getUTCTimeOrEmpty ( expiryTime ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_EXPIRY , stopString ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_RESOURCE , resourceTypes ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_IP , ipRange != null ? ipRange . toString ( ) : null ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_PROTOCOLS , protocols != null ? protocols . toString ( ) : null ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNATURE , signature ) ; return builder ;


signature:
public class SharedAccessSignatureHelper { /** * Get the complete query builder for creating the Shared Access Signature query .
 * @ param policy
 * The shared access policy for the shared access signature .
 * @ param headers
 * The optional header values to set for a blob or file accessed with this shared access signature .
 * @ param groupPolicyIdentifier
 * An optional identifier for the policy .
 * @ param resourceType
 * Either " b " for blobs , " c " for containers , " f " for files , or " s " for shares .
 * @ param ipRange
 * The range of IP addresses for the shared access signature .
 * @ param protocols
 * The Internet protocols for the shared access signature .
 * @ param signature
 * The signature to use .
 * @ return The finished query builder
 * @ throws IllegalArgumentException
 * @ throws StorageException */
public static UriQueryBuilder generateSharedAccessSignatureForBlobAndFile ( final SharedAccessPolicy policy , final SharedAccessHeaders headers , final String groupPolicyIdentifier , final String resourceType , final IPRange ipRange , final SharedAccessProtocols protocols , final String signature ) throws StorageException { } }

implementation:
Utility . assertNotNullOrEmpty ( "resourceType" , resourceType ) ; return generateSharedAccessSignatureHelper ( policy , null /* startPartitionKey */
, null /* startRowKey */
, null /* endPartitionKey */
, null /* endRowKey */
, groupPolicyIdentifier , resourceType , ipRange , protocols , null /* tableName */
, signature , headers ) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the complete query builder for creating the Shared Access Signature query .
 * @ param policy
 * The shared access policy for the shared access signature .
 * @ param groupPolicyIdentifier
 * An optional identifier for the policy .
 * @ param ipRange
 * The range of IP addresses for the shared access signature .
 * @ param protocols
 * The Internet protocols for the shared access signature .
 * @ param signature
 * The signature to use .
 * @ return The finished query builder
 * @ throws IllegalArgumentException
 * @ throws StorageException */
public static UriQueryBuilder generateSharedAccessSignatureForQueue ( final SharedAccessQueuePolicy policy , final String groupPolicyIdentifier , final IPRange ipRange , final SharedAccessProtocols protocols , final String signature ) throws StorageException { } }

implementation:
return generateSharedAccessSignatureHelper ( policy , null /* startPartitionKey */
, null /* startRowKey */
, null /* endPartitionKey */
, null /* endRowKey */
, groupPolicyIdentifier , null /* resourceType */
, ipRange , protocols , null /* tableName */
, signature , null /* headers */
) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the complete query builder for creating the Shared Access Signature query .
 * @ param policy
 * The shared access policy for the shared access signature .
 * @ param startPartitionKey
 * An optional restriction of the beginning of the range of partition keys to include .
 * @ param startRowKey
 * An optional restriction of the beginning of the range of row keys to include .
 * @ param endPartitionKey
 * An optional restriction of the end of the range of partition keys to include .
 * @ param endRowKey
 * An optional restriction of the end of the range of row keys to include .
 * @ param accessPolicyIdentifier
 * An optional identifier for the policy .
 * @ param ipRange
 * The range of IP addresses for the shared access signature .
 * @ param protocols
 * The Internet protocols for the shared access signature .
 * @ param tableName
 * The table name .
 * @ param signature
 * The signature to use .
 * @ return The finished query builder
 * @ throws IllegalArgumentException
 * @ throws StorageException */
public static UriQueryBuilder generateSharedAccessSignatureForTable ( final SharedAccessTablePolicy policy , final String startPartitionKey , final String startRowKey , final String endPartitionKey , final String endRowKey , final String accessPolicyIdentifier , final IPRange ipRange , final SharedAccessProtocols protocols , final String tableName , final String signature ) throws StorageException { } }

implementation:
Utility . assertNotNull ( "tableName" , tableName ) ; return generateSharedAccessSignatureHelper ( policy , startPartitionKey , startRowKey , endPartitionKey , endRowKey , accessPolicyIdentifier , null /* resourceType */
, ipRange , protocols , tableName , signature , null /* headers */
) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature for a { @ link CloudStorageAccount } .
 * @ param accountName
 * The name of the account to use for the SAS .
 * @ param policy
 * The shared access policy to hash .
 * @ param ipRange
 * An optional range of IP addresses .
 * @ param protocols
 * An optional restriction of allowed protocols .
 * @ param creds
 * The { @ link StorageCredentials } associated with the object .
 * @ return The signature hash embedded inside the Shared Access Signature .
 * @ throws InvalidKeyException
 * @ throws StorageException */
public static String generateSharedAccessSignatureHashForAccount ( final String accountName , final SharedAccessAccountPolicy policy , final StorageCredentials creds ) throws InvalidKeyException , StorageException { } }

implementation: Utility . assertNotNullOrEmpty ( "resource" , accountName ) ; Utility . assertNotNull ( "credentials" , creds ) ; String permissions = null ; Date startTime = null ; Date expiryTime = null ; IPRange ipRange = null ; SharedAccessProtocols protocols = null ; String services = null ; String resourceTypes = null ; if ( policy != null ) { permissions = policy . permissionsToString ( ) ; startTime = policy . getSharedAccessStartTime ( ) ; expiryTime = policy . getSharedAccessExpiryTime ( ) ; ipRange = policy . getRange ( ) ; protocols = policy . getProtocols ( ) ; services = policy . servicesToString ( ) ; resourceTypes = policy . resourceTypesToString ( ) ; } String stringToSign = String . format ( "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" , accountName , permissions == null ? Constants . EMPTY_STRING : permissions , services , resourceTypes , Utility . getUTCTimeOrEmpty ( startTime ) , Utility . getUTCTimeOrEmpty ( expiryTime ) , ipRange == null ? Constants . EMPTY_STRING : ipRange . toString ( ) , protocols == null ? Constants . EMPTY_STRING : protocols . toString ( ) , Constants . HeaderConstants . TARGET_STORAGE_VERSION ) ; return generateSharedAccessSignatureHashHelper ( stringToSign , creds ) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature for the blob or file service .
 * @ param policy
 * The shared access policy to hash .
 * @ param headers
 * The optional header values to set for a blob or file accessed with this shared access signature .
 * @ param accessPolicyIdentifier
 * An optional identifier for the policy .
 * @ param resourceName
 * The resource name .
 * @ param ipRange
 * The range of IP addresses to hash .
 * @ param protocols
 * The Internet protocols to hash .
 * @ param client
 * The ServiceClient associated with the object .
 * @ return The signature hash embedded inside the Shared Access Signature .
 * @ throws InvalidKeyException
 * @ throws StorageException */
public static String generateSharedAccessSignatureHashForBlobAndFile ( final SharedAccessPolicy policy , SharedAccessHeaders headers , final String accessPolicyIdentifier , final String resourceName , final IPRange ipRange , final SharedAccessProtocols protocols , final ServiceClient client ) throws InvalidKeyException , StorageException { } }

implementation: String stringToSign = generateSharedAccessSignatureStringToSign ( policy , resourceName , ipRange , protocols , accessPolicyIdentifier ) ; String cacheControl = null ; String contentDisposition = null ; String contentEncoding = null ; String contentLanguage = null ; String contentType = null ; if ( headers != null ) { cacheControl = headers . getCacheControl ( ) ; contentDisposition = headers . getContentDisposition ( ) ; contentEncoding = headers . getContentEncoding ( ) ; contentLanguage = headers . getContentLanguage ( ) ; contentType = headers . getContentType ( ) ; } stringToSign = String . format ( "%s\n%s\n%s\n%s\n%s\n%s" , stringToSign , cacheControl == null ? Constants . EMPTY_STRING : cacheControl , contentDisposition == null ? Constants . EMPTY_STRING : contentDisposition , contentEncoding == null ? Constants . EMPTY_STRING : contentEncoding , contentLanguage == null ? Constants . EMPTY_STRING : contentLanguage , contentType == null ? Constants . EMPTY_STRING : contentType ) ; return generateSharedAccessSignatureHashHelper ( stringToSign , client . getCredentials ( ) ) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature for queue service .
 * @ param policy
 * The shared access policy to hash .
 * @ param accessPolicyIdentifier
 * An optional identifier for the policy .
 * @ param resourceName
 * The resource name .
 * @ param ipRange
 * The range of IP addresses to hash .
 * @ param protocols
 * The Internet protocols to hash .
 * @ param client
 * The ServiceClient associated with the object .
 * @ return The signature hash embedded inside the Shared Access Signature .
 * @ throws InvalidKeyException
 * @ throws StorageException */
public static String generateSharedAccessSignatureHashForQueue ( final SharedAccessQueuePolicy policy , final String accessPolicyIdentifier , final String resourceName , final IPRange ipRange , final SharedAccessProtocols protocols , final ServiceClient client ) throws InvalidKeyException , StorageException { } }

implementation: final String stringToSign = generateSharedAccessSignatureStringToSign ( policy , resourceName , ipRange , protocols , accessPolicyIdentifier ) ; return generateSharedAccessSignatureHashHelper ( stringToSign , client . getCredentials ( ) ) ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature for the table service .
 * @ param policy
 * The shared access policy to hash .
 * @ param accessPolicyIdentifier
 * An optional identifier for the policy .
 * @ param resourceName
 * The resource name .
 * @ param ipRange
 * The range of IP addresses to hash .
 * @ param protocols
 * The Internet protocols to hash .
 * @ param startPartitionKey
 * An optional restriction of the beginning of the range of partition keys to hash .
 * @ param startRowKey
 * An optional restriction of the beginning of the range of row keys to hash .
 * @ param endPartitionKey
 * An optional restriction of the end of the range of partition keys to hash .
 * @ param endRowKey
 * An optional restriction of the end of the range of row keys to hash .
 * @ param client
 * The ServiceClient associated with the object .
 * @ return The signature hash embedded inside the Shared Access Signature .
 * @ throws InvalidKeyException
 * @ throws StorageException */
public static String generateSharedAccessSignatureHashForTable ( final SharedAccessTablePolicy policy , final String accessPolicyIdentifier , final String resourceName , final IPRange ipRange , final SharedAccessProtocols protocols , final String startPartitionKey , final String startRowKey , final String endPartitionKey , final String endRowKey , final ServiceClient client ) throws InvalidKeyException , StorageException { } }

implementation: String stringToSign = generateSharedAccessSignatureStringToSign ( policy , resourceName , ipRange , protocols , accessPolicyIdentifier ) ; stringToSign = String . format ( "%s\n%s\n%s\n%s\n%s" , stringToSign , startPartitionKey == null ? Constants . EMPTY_STRING : startPartitionKey , startRowKey == null ? Constants . EMPTY_STRING : startRowKey , endPartitionKey == null ? Constants . EMPTY_STRING : endPartitionKey , endRowKey == null ? Constants . EMPTY_STRING : endRowKey ) ; return generateSharedAccessSignatureHashHelper ( stringToSign , client . getCredentials ( ) ) ;


signature:
public class SharedAccessSignatureHelper { /** * Parses the query parameters and populates a StorageCredentialsSharedAccessSignature object if one is present .
 * @ param completeUri
 * A { @ link StorageUri } object which represents the complete Uri .
 * @ return The StorageCredentialsSharedAccessSignature if one is present , otherwise null .
 * @ throws StorageException
 * An exception representing any error which occurred during the operation . */
public static StorageCredentialsSharedAccessSignature parseQuery ( final StorageUri completeUri ) throws StorageException { } }

implementation: final HashMap < String , String [ ] > queryParameters = PathUtility . parseQueryString ( completeUri . getQuery ( ) ) ; return parseQuery ( queryParameters ) ;


signature:
public class SharedAccessSignatureHelper { /** * Parses the query parameters and populates a StorageCredentialsSharedAccessSignature object if one is present .
 * @ param queryParams
 * The parameters to parse .
 * @ return The StorageCredentialsSharedAccessSignature if one is present , otherwise null .
 * @ throws StorageException
 * An exception representing any error which occurred during the operation . */
public static StorageCredentialsSharedAccessSignature parseQuery ( final HashMap < String , String [ ] > queryParams ) throws StorageException { } }

implementation: boolean sasParameterFound = false ; List < String > removeList = new ArrayList < String > ( ) ; for ( final Entry < String , String [ ] > entry : queryParams . entrySet ( ) ) { final String lowerKey = entry . getKey ( ) . toLowerCase ( Utility . LOCALE_US ) ; if ( lowerKey . equals ( Constants . QueryConstants . SIGNATURE ) ) { sasParameterFound = true ; } else if ( lowerKey . equals ( Constants . QueryConstants . COMPONENT ) ) { removeList . add ( entry . getKey ( ) ) ; } else if ( lowerKey . equals ( Constants . QueryConstants . RESOURCETYPE ) ) { removeList . add ( entry . getKey ( ) ) ; } else if ( lowerKey . equals ( Constants . QueryConstants . SNAPSHOT ) ) { removeList . add ( entry . getKey ( ) ) ; } else if ( lowerKey . equals ( Constants . QueryConstants . API_VERSION ) ) { removeList . add ( entry . getKey ( ) ) ; } } for ( String removeParam : removeList ) { queryParams . remove ( removeParam ) ; } if ( sasParameterFound ) { final UriQueryBuilder builder = new UriQueryBuilder ( ) ; StringBuilder values = new StringBuilder ( ) ; for ( final Entry < String , String [ ] > entry : queryParams . entrySet ( ) ) { values . setLength ( 0 ) ; for ( int i = 0 ; i < entry . getValue ( ) . length ; i ++ ) { values . append ( entry . getValue ( ) [ i ] ) ; values . append ( ',' ) ; } values . deleteCharAt ( values . length ( ) - 1 ) ; addIfNotNullOrEmpty ( builder , entry . getKey ( ) . toLowerCase ( ) , values . toString ( ) ) ; } return new StorageCredentialsSharedAccessSignature ( builder . toString ( ) ) ; } return null ;


signature:
public class SharedAccessSignatureHelper { /** * Helper to add a name / value pair to a < code > UriQueryBuilder < / code > if the value is not null or empty .
 * @ param builder
 * The builder to add to .
 * @ param name
 * The name to add .
 * @ param val
 * The value to add if not null or empty .
 * @ throws StorageException
 * An exception representing any error which occurred during the operation . */
private static void addIfNotNullOrEmpty ( UriQueryBuilder builder , String name , String val ) throws StorageException { } }

implementation: if ( ! Utility . isNullOrEmpty ( val ) ) { builder . add ( name , val ) ; }


signature:
public class SharedAccessSignatureHelper { /** * Get the complete query builder for creating the Shared Access Signature query .
 * @ param policy
 * A { @ link SharedAccessPolicy } containing the permissions for the SAS .
 * @ param startPartitionKey
 * The start partition key for a shared access signature URI .
 * @ param startRowKey
 * The start row key for a shared access signature URI .
 * @ param endPartitionKey
 * The end partition key for a shared access signature URI .
 * @ param endRowKey
 * The end row key for a shared access signature URI .
 * @ param accessPolicyIdentifier
 * An optional identifier for the policy .
 * @ param resourceType
 * The resource type for a shared access signature URI .
 * @ param ipRange
 * The range of IP addresses for the shared access signature .
 * @ param protocols
 * The Internet protocols for the shared access signature .
 * @ param tableName
 * The table name .
 * @ param signature
 * The signature hash .
 * @ param headers
 * Optional blob or file headers .
 * @ return The finished query builder .
 * @ throws StorageException
 * An exception representing any error which occurred during the operation . */
private static UriQueryBuilder generateSharedAccessSignatureHelper ( final SharedAccessPolicy policy , final String startPartitionKey , final String startRowKey , final String endPartitionKey , final String endRowKey , final String accessPolicyIdentifier , final String resourceType , final IPRange ipRange , final SharedAccessProtocols protocols , final String tableName , final String signature , final SharedAccessHeaders headers ) throws StorageException { } }

implementation: Utility . assertNotNull ( "signature" , signature ) ; String permissions = null ; Date startTime = null ; Date expiryTime = null ; if ( policy != null ) { permissions = policy . permissionsToString ( ) ; startTime = policy . getSharedAccessStartTime ( ) ; expiryTime = policy . getSharedAccessExpiryTime ( ) ; } final UriQueryBuilder builder = new UriQueryBuilder ( ) ; builder . add ( Constants . QueryConstants . SIGNED_VERSION , Constants . HeaderConstants . TARGET_STORAGE_VERSION ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_PERMISSIONS , permissions ) ; final String startString = Utility . getUTCTimeOrEmpty ( startTime ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_START , startString ) ; final String stopString = Utility . getUTCTimeOrEmpty ( expiryTime ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_EXPIRY , stopString ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . START_PARTITION_KEY , startPartitionKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . START_ROW_KEY , startRowKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . END_PARTITION_KEY , endPartitionKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . END_ROW_KEY , endRowKey ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_IDENTIFIER , accessPolicyIdentifier ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_RESOURCE , resourceType ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_IP , ipRange != null ? ipRange . toString ( ) : null ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNED_PROTOCOLS , protocols != null ? protocols . toString ( ) : null ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SAS_TABLE_NAME , tableName ) ; if ( headers != null ) { addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CACHE_CONTROL , headers . getCacheControl ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_TYPE , headers . getContentType ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_ENCODING , headers . getContentEncoding ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_LANGUAGE , headers . getContentLanguage ( ) ) ; addIfNotNullOrEmpty ( builder , Constants . QueryConstants . CONTENT_DISPOSITION , headers . getContentDisposition ( ) ) ; } addIfNotNullOrEmpty ( builder , Constants . QueryConstants . SIGNATURE , signature ) ; return builder ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature .
 * @ param stringToSign
 * The string to decode and hash
 * @ param creds
 * Reference to the { @ link StorageCredentials . } .
 * @ return The signature hash embedded inside the Shared Access Signature .
 * @ throws InvalidKeyException
 * @ throws StorageException */
private static String generateSharedAccessSignatureHashHelper ( String stringToSign , final StorageCredentials creds ) throws StorageException , InvalidKeyException { } }

implementation: Utility . assertNotNull ( "credentials" , creds ) ; Logger . debug ( null , LogConstants . SIGNING , stringToSign ) ; stringToSign = Utility . safeDecode ( stringToSign ) ; final String signature = StorageCredentialsHelper . computeHmac256 ( creds , stringToSign ) ; Logger . verbose ( null , LogConstants . SIGNING , stringToSign ) ; return signature ;


signature:
public class SharedAccessSignatureHelper { /** * Get the signature hash embedded inside the Shared Access Signature .
 * @ param policy
 * A { @ link SharedAccessPolicy } containing the permissions for the SAS .
 * @ param resource
 * The canonical resource ( or resource type ) string , unescaped .
 * @ param ipRange
 * The range of IP addresses to hash .
 * @ param protocols
 * The Internet protocols to hash .
 * @ param headers
 * The optional header values to set for a blob or file accessed with this shared access signature .
 * @ param accessPolicyIdentifier
 * An optional identifier for the policy .
 * @ return The signature hash embedded inside the Shared Access Signature .
 * @ throws InvalidKeyException
 * @ throws StorageException */
private static String generateSharedAccessSignatureStringToSign ( final SharedAccessPolicy policy , final String resource , final IPRange ipRange , final SharedAccessProtocols protocols , final String accessPolicyIdentifier ) throws InvalidKeyException , StorageException { } }

implementation: Utility . assertNotNullOrEmpty ( "resource" , resource ) ; String permissions = null ; Date startTime = null ; Date expiryTime = null ; if ( policy != null ) { permissions = policy . permissionsToString ( ) ; startTime = policy . getSharedAccessStartTime ( ) ; expiryTime = policy . getSharedAccessExpiryTime ( ) ; } String stringToSign = String . format ( "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s" , permissions == null ? Constants . EMPTY_STRING : permissions , Utility . getUTCTimeOrEmpty ( startTime ) , Utility . getUTCTimeOrEmpty ( expiryTime ) , resource , accessPolicyIdentifier == null ? Constants . EMPTY_STRING : accessPolicyIdentifier , ipRange == null ? Constants . EMPTY_STRING : ipRange . toString ( ) , protocols == null ? Constants . EMPTY_STRING : protocols . toString ( ) , Constants . HeaderConstants . TARGET_STORAGE_VERSION ) ; return stringToSign ;