@Pure
	@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
	public static URL getParentURL(URL url) throws MalformedURLException {
		if (url == null) {
			return url;
		}
		String path = url.getPath();
		final String prefix;
		final String parentStr;

		switch (URISchemeType.getSchemeType(url)) {
		case JAR:
			final int index = path.indexOf(JAR_URL_FILE_ROOT);
			assert index > 0;
			prefix = path.substring(0, index + 1);
			path = path.substring(index + 1);
			parentStr = URL_PATH_SEPARATOR;
			break;
		case FILE:
			prefix = null;
			parentStr = ".." + URL_PATH_SEPARATOR; //$NON-NLS-1$
			break;
			//$CASES-OMITTED$
		default:
			prefix = null;
			parentStr = URL_PATH_SEPARATOR;
		}

		if (path == null || "".equals(path)) { //$NON-NLS-1$
			path = parentStr;
		}
		int index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
		if (index == -1) {
			path = parentStr;
		} else if (index == path.length() - 1) {
			index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR, index - 1);
			if (index == -1) {
				path = parentStr;
			} else {
				path = path.substring(0, index + 1);
			}
		} else {
			path = path.substring(0, index + 1);
		}

		if (prefix != null) {
			path = prefix + path;
		}

		return new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
	}
@ Pure @ SuppressWarnings ( { "checkstyle:cyclomaticcomplexity" , "checkstyle:npathcomplexity" } ) public static URL getParentURL ( URL url ) throws MalformedURLException { if ( url == null ) { return url ; } String path = url . getPath ( ) ; final String prefix ; final String parentStr ; switch ( URISchemeType . getSchemeType ( url ) ) { case JAR : final int index = path . indexOf ( JAR_URL_FILE_ROOT ) ; assert index > 0 ; prefix = path . substring ( 0 , index + 1 ) ; path = path . substring ( index + 1 ) ; parentStr = URL_PATH_SEPARATOR ; break ; case FILE : prefix = null ; parentStr = ".." + URL_PATH_SEPARATOR ; break ; default : prefix = null ; parentStr = URL_PATH_SEPARATOR ; } if ( path == null || "" . equals ( path ) ) { path = parentStr ; } int index = path . lastIndexOf ( URL_PATH_SEPARATOR_CHAR ) ; if ( index == - 1 ) { path = parentStr ; } else if ( index == path . length ( ) - 1 ) { index = path . lastIndexOf ( URL_PATH_SEPARATOR_CHAR , index - 1 ) ; if ( index == - 1 ) { path = parentStr ; } else { path = path . substring ( 0 , index + 1 ) ; } } else { path = path . substring ( 0 , index + 1 ) ; } if ( prefix != null ) { path = prefix + path ; } return new URL ( url . getProtocol ( ) , url . getHost ( ) , url . getPort ( ) , path ) ; }
Replies the parent URL for the given URL.

@param url the URL.
@return the parent URL
@throws MalformedURLException if the parent URL cannot be built.