Makes an educated guess of the mime type of the resource pointed by this url.
It tries to extract an 'extension' part and confronts this extension to the list of known extensions.
@param url the url
@return the mime type, BINARY if not found.
430586
public static String getMimeTypeForFile(URL url) {
        if (url == null) {
            //The input url is null so we can't retrieve a mimetype, therefore we return null.
            return null;
        }
        String external = url.toExternalForm();
        if (external.indexOf('.') == -1) {
            return BINARY;
        } else {
            String ext = external.substring(external.lastIndexOf('.') + 1);
            String mime = KnownMimeTypes.getMimeTypeByExtension(ext);
            if (mime == null) {
                return BINARY;
            } else {
                return mime;
            }
        }
    }
627064
public static String getURLPath(String url) {
		url = stripURLScheme(url);
		int pathIdx = url.indexOf(UrlOperations.PATH_START);
		if(pathIdx == -1) {
			return "/";
		}
		return url.substring(pathIdx);
	}
245515
private static final String getExtension(String MIMETYPE) throws Exception {
        if (m_extensionMappings == null) {
            m_extensionMappings = readExtensionMappings(Server.FEDORA_HOME + "/server/" + Server.CONFIG_DIR + "/" + DATASTREAM_MAPPING_SOURCE_FILE);
        }

        String extension = m_extensionMappings.get(MIMETYPE);
        if (extension != null) {
            return extension;
        } else {
            return "";
        }
    }
1338862
public static UrlParts parseUrl(String theUrl) {
		String url = theUrl;
		UrlParts retVal = new UrlParts();
		if (url.startsWith("http")) {
			if (url.startsWith("/")) {
				url = url.substring(1);
			}

			int qmIdx = url.indexOf('?');
			if (qmIdx != -1) {
				retVal.setParams(defaultIfBlank(url.substring(qmIdx + 1), null));
				url = url.substring(0, qmIdx);
			}

			IdDt id = new IdDt(url);
			retVal.setResourceType(id.getResourceType());
			retVal.setResourceId(id.getIdPart());
			retVal.setVersionId(id.getVersionIdPart());
			return retVal;
		}
		if (url.matches("/[a-zA-Z]+\\?.*")) {
			url = url.substring(1);
		}
		int nextStart = 0;
		boolean nextIsHistory = false;

		for (int idx = 0; idx < url.length(); idx++) {
			char nextChar = url.charAt(idx);
			boolean atEnd = (idx + 1) == url.length();
			if (nextChar == '?' || nextChar == '/' || atEnd) {
				int endIdx = (atEnd && nextChar != '?') ? idx + 1 : idx;
				String nextSubstring = url.substring(nextStart, endIdx);
				if (retVal.getResourceType() == null) {
					retVal.setResourceType(nextSubstring);
				} else if (retVal.getResourceId() == null) {
					retVal.setResourceId(nextSubstring);
				} else if (nextIsHistory) {
					retVal.setVersionId(nextSubstring);
				} else {
					if (nextSubstring.equals(Constants.URL_TOKEN_HISTORY)) {
						nextIsHistory = true;
					} else {
						throw new InvalidRequestException("Invalid FHIR resource URL: " + url);
					}
				}
				if (nextChar == '?') {
					if (url.length() > idx + 1) {
						retVal.setParams(url.substring(idx + 1, url.length()));
					}
					break;
				}
				nextStart = idx + 1;
			}
		}

		return retVal;

	}
1335242
public static String read(URL url) throws IOException, NotFoundException {
        BufferedImage image = ImageIO.read(url);
        return read(image);
    }
1219425
public String applyOnURL(String url) {
        if (StringUtils.isBlank(url)) {
            return url;
        }
        return StringUtils.substringBefore(url, "?") + toString();
    }
438981
@Override
    public String getContentType() {
        if (url.getFile().endsWith("!/")) {
            // the type for jar file itself is always "x-java/jar"
            return "x-java/jar";
        }
        String cType = null;
        String entryName = getEntryName();

        if (entryName != null) {
            // if there is an Jar Entry, get the content type from the name
            cType = guessContentTypeFromName(entryName);
        } else {
            try {
                connect();
                cType = jarFileURLConnection.getContentType();
            } catch (IOException ioe) {
                // Ignore
            }
        }
        if (cType == null) {
            cType = "content/unknown";
        }
        return cType;
    }
331409
private MediaType findContentType(final String url) {
        if (url == null) {
            return null;
        }

        if (url.startsWith("file")) {
            return APPLICATION_OCTET_STREAM_TYPE;
        } else if (url.startsWith("http")) {
            try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                final HttpHead httpHead = new HttpHead(url);
                try (CloseableHttpResponse response = httpClient.execute(httpHead)) {
                    if (response.getStatusLine().getStatusCode() == SC_OK) {
                        final Header contentType = response.getFirstHeader(CONTENT_TYPE);
                        if (contentType != null) {
                            return MediaType.valueOf(contentType.getValue());
                        }
                    }
                }
            } catch (final IOException e) {
                LOGGER.warn("Unable to retrieve external content from {} due to {}", url, e.getMessage());
            } catch (final Exception e) {
                throw new RepositoryRuntimeException(e);
            }
        }
        LOGGER.debug("Defaulting to octet stream for media type");
        return APPLICATION_OCTET_STREAM_TYPE;
    }
219848
function getSourceType(url) {
        var origin = url;
        url = url.toLowerCase();

        if (url.match(/\.(jpeg|jpg|gif|png|apn|webp|svg)$/) !== null) {
            return 'image';
        }
        if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/)) {
            return 'video';
        }
        if (url.match(/vimeo\.com\/([0-9]*)/)) {
            return 'video';
        }
        if (url.match(/\.(mp4|ogg|webm)$/) !== null) {
            return 'video';
        }

        // Check if inline content
        if (url.indexOf("#") > -1) {
            var hash = origin.split('#').pop();
            if (hash.trim() !== '') {
                return 'inline';
            }
        }
        // Ajax
        if (url.includes("gajax=true")) {
            return 'ajax';
        }

        return 'external';
    }
20705
public static byte[] getBytes(URL url) throws IOException {
        final String path = url.getPath();
        final File file = new File(path);
        if (file.exists()) {
            return getFileBytes(file);
        }

        return null;
    }
506553
public static Service identify(String url) {
    Service answer = Service.UNSUPPORTED;
    int index = url.indexOf(COMPOSUM_URL);
    if (index > 0) {
      answer = Service.COMPOSUM;
    }
    else {
      index = url.indexOf(CRX_URL);
      if (index > 0) {
        answer = Service.CRX;
      }
    }
    return answer;
  }
1103436
public static boolean isExternalUrl(String url) {
        return URL_PATTERN.matcher(url).matches() || SPECIAL_URL_PATTERN.matcher(url).matches();
    }
525610
public static boolean isExtensionMatch(String uriName, String urlPattern) {
        if (urlPattern.startsWith("*.")) {
            String ext = urlPattern.substring(1);
            if (uriName.endsWith(ext)) {
                return true;
            }
        }
        return false;
    }
42110
public static RepositoryId extractRepositoryFromScmUrl(String url) {
		if (StringUtils.isEmpty(url))
			return null;
		int ghIndex = url.indexOf(HOST_DEFAULT);
		if (ghIndex == -1 || ghIndex + 1 >= url.length())
			return null;
		if (!url.endsWith(SUFFIX_GIT))
			return null;
		url = url.substring(ghIndex + HOST_DEFAULT.length() + 1, url.length()
				- SUFFIX_GIT.length());
		return RepositoryId.createFromId(url);
	}
1346031
protected String getBaseUrl(String url) {
    	if (url.endsWith("/")) {
    	    return url.substring(0, url.length() - 1);
    	}
    	else {
    	    return url;
    	}
    	
    }
1054866
private String getAssetAsString(String url)
   {
      InputStream is = null;
      try
      {
         is = assetManager.open(url);

         Reader r = new InputStreamReader(is, Charset.forName("UTF-8"));
         char[]         buffer = new char[4096];
         StringBuilder  sb = new StringBuilder();
         int            len = r.read(buffer);
         while (len > 0) {
            sb.append(buffer, 0, len);
            len = r.read(buffer);
         }
         return sb.toString();
      }
      catch (IOException e)
      {
         return null;
      }
      finally {
         try {
            if (is != null)
               is.close();
         } catch (IOException e) {
           // Do nothing
         }
      }
   }
1014450
@Pure
	@Inline(value = "URISchemeType.JAR.isURL($1)", imported = {URISchemeType.class})
	public static boolean isJarURL(URL url) {
		return URISchemeType.JAR.isURL(url);
	}