microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java
protected static String getParentNameFromURI(final StorageUri resourceAddress, final CloudFileShare share)
            throws URISyntaxException {
        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;
    }
protected static String getParentNameFromURI(final StorageUri resourceAddress, final CloudFileShare share)
            throws URISyntaxException {
        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;
    }
protected static String getParentNameFromURI ( final StorageUri resourceAddress , final CloudFileShare share ) throws URISyntaxException { 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 ; }
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
Retrieves the parent name for a file URI .