Determine whether the given URL points to a resource in a jar file,
that is, has protocol "jar", "zip", "vfszip" or "wsjar".

@param url the URL to check
@return whether the URL has been identified as a JAR URL
552698
public static boolean isJarURL(URL url) {
        String protocol = url.getProtocol();
        return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) ||
                URL_PROTOCOL_VFSZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol));
    }
472787
public final PathImpl lookup(URL url)
  {
    String name = URLDecoder.decode(url.toString());

    return lookup(name, null);
  }
217370
public static File getCanonicalFileFromFileUrl(final URL url) {
        File file = null;
        if (url == null) {
            throw new NullPointerException("The URL cannot be null.");
        }
        if ("file".equals(url.getProtocol())) {
            final String fileName = url.getFile();
            final String path = URLUtils.uncorrect(fileName);
            file = new File(path);

            try {
                file = file.getCanonicalFile();
            } catch (final IOException e) {
                // Does not exist.
                file = file.getAbsoluteFile();
            }

        }
        return file;
    }
984144
public static boolean isFileURL(URL url) {
        String protocol = url.getProtocol();
        return (URL_PROTOCOL_FILE.equals(protocol) || protocol.startsWith(URL_PROTOCOL_VFS));
    }
642215
public boolean containsResource (String path)
    {
        try {
            if (resolveJarFile()) {
                return false;
            }
            return (_jarSource.getJarEntry(path) != null);
        } catch (IOException ioe) {
            return false;
        }
    }
770686
public static boolean showDocument(URL url)
	{
		if ( url != null ){
			boolean success = JNLPProxy.showDocument(url);
			if ( ! success)
				logger.info("could not open URL "+url+" in browser. check your config or browser version.");
		return success;

		}
		else
			return false;
	}
556091
public static boolean isHttp(String url) {
		if (url.length() < 7 || !url.startsWith("http")) {
			return false;
		}
		int i = 4; // "http"
		if (url.charAt(i) == 's') {
			i++;
		}
		return url.startsWith("://", i);
	}
1041943
private static String parseRelativeURL(URL url, String spec) {
        String path = url.getPath();
        String result;

        int index = path.indexOf("!/");
        if (index == -1) {
            // The "jar" protocol requires that the path contain an entry path.
            // For backwards compatibility, we do not.  Instead, we just
            // canonicalize the base URL.
            try {
                url = Utils.newURL(Utils.newURL(path), spec);
            } catch (MalformedURLException ex) {
                throw new RuntimeException(ex);
            }

            result = url.toString();
        } else {
            String entry;

            if (spec.startsWith("/")) {
                // This is an absolute entry path, so we ignore the existing
                // entry path.
                entry = canonicalize(spec);
            } else {
                // Extract the existing entry path.
                entry = path.substring(index + 1);

                if (entry.endsWith("/")) {
                    // The entry ends with '/', so we can directly append the
                    // relative entry path.
                    entry = canonicalize(entry + spec);
                } else if (entry.endsWith("/.")) {
                    // We don't want the logic below because "." is not a
                    // "true" basename.
                    entry = canonicalize(entry + '/' + spec);
                } else {
                    // Strip off the basename with a ".." path segment and
                    // append the relative entry path.
                    entry = canonicalize(entry + "/../" + spec);
                }
            }

            result = path.substring(0, index) + '!' + entry;
        }
        return result;
    }
1106654
public static String getHostFromURL(String url) {
		URL u = toURL(url);
		String host = (u == null) ? "" : u.getHost();
		return host;
	}
1143694
private Set<String> getResourceNamesFromJar(String path, URL resourceURL) {

		URLConnection con = null;

		try {
			if (resourceURL.toString().startsWith(JawrConstant.JAR_URL_PREFIX)) {
				con = resourceURL.openConnection();
			}
		} catch (IOException e) {

			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			return Collections.emptySet();
		}

		JarFile jarFile;
		String jarFileUrl;
		String rootEntryPath;
		boolean newJarFile = false;

		try {
			if (con instanceof JarURLConnection) {
				// Should usually be the case for traditional JAR files.
				JarURLConnection jarCon = (JarURLConnection) con;
				jarCon.setUseCaches(true);
				jarFile = jarCon.getJarFile();
				JarEntry jarEntry = jarCon.getJarEntry();
				rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
			} else {
				// No JarURLConnection -> need to resort to URL file parsing.
				// We'll assume URLs of the format "jar:path!/entry", with the
				// protocol
				// being arbitrary as long as following the entry format.
				// We'll also handle paths with and without leading "file:"
				// prefix.
				String urlFile = resourceURL.getFile();
				int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
				if (separatorIndex != -1) {
					jarFileUrl = urlFile.substring(0, separatorIndex);
					rootEntryPath = urlFile.substring(separatorIndex + JAR_URL_SEPARATOR.length());
					jarFile = getJarFile(jarFileUrl);
				} else {
					jarFile = new JarFile(urlFile);
					rootEntryPath = "";
				}
				newJarFile = true;
			}
		} catch (IOException e) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			return Collections.emptySet();
		}
		try {
			if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
				// Root entry path must end with slash to allow for proper
				// matching.
				// The Sun JRE does not return a slash here, but BEA JRockit
				// does.
				rootEntryPath = rootEntryPath + "/";
			}
			Set<String> result = new LinkedHashSet<>(8);
			for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
				JarEntry entry = entries.nextElement();
				String entryPath = entry.getName();
				if (isDirectChildPath(rootEntryPath, entryPath)) {
					String relativePath = entryPath.substring(rootEntryPath.length());
					result.add(relativePath);
				}
			}
			return result;
		} finally {
			// Close jar file, but only if freshly obtained -
			// not from JarURLConnection, which might cache the file reference.
			if (newJarFile) {
				try {
					jarFile.close();
				} catch (IOException e) {
					// Nothing to do
				}
			}
		}
	}
1186468
public static URL switchFromZipToJarProtocolIfNeeded(URL resourceUrl)
      throws MalformedURLException {
    final String protocol = resourceUrl.getProtocol();
    // If zip protocol switch to jar protocol
    if ("zip".equals(protocol)
        && resourceUrl.getPath().contains(".jar" + JAR_URL_SEPARATOR)) {
      String filePath = resourceUrl.getFile();
      if (!filePath.startsWith("/")) {
        filePath = "/" + filePath;
      }
      return new URL("jar:file:" + filePath);
    }
    return resourceUrl;
  }
17635
public static String urlToString(URL url) {
        return Checker.isNull(url) ? "" : url.toString().replaceAll("file:" + (Checker.isWindows() ? "/?" : ""), "");
    }
965347
public static String getRequestLink(String url) {

        if (CmsStringUtil.isEmpty(url)) {
            return null;
        }
        int pos = url.indexOf(URL_DELIMITER);
        if (pos >= 0) {
            return url.substring(0, pos);
        }
        return url;

    }
1288141
static String [] searchJarFSForClasses( URL url ) throws IOException {
        try {
            try {
                FileSystems.newFileSystem(url.toURI(), new HashMap<>());
            } catch (FileSystemAlreadyExistsException e) { /* ignore */ }

            Path path = FileSystems.getFileSystem(url.toURI()).getPath("/");

            return Files.walk(path).map(Path::toString)
                    .filter(BshClassPath::isClassFileName)
                    .map(BshClassPath::canonicalizeClassName)
                    .toArray(String[]::new);
        } catch (URISyntaxException e) { /* ignore */ }
        return new String[0];
    }
684993
public static boolean hasVersionString(String url) {
        boolean inVersion = false;
        for (int i = 0; i < url.length(); i++) {
            char c = url.charAt(i);
            if (c == 'v') {
                inVersion = true;
            } else if (Character.isDigit(c) && inVersion) {
                return true;
            } else {
                inVersion = false;
            }


        }

        return false;
    }
325936
public URL findResource(String fileName) {
		Object location = this.mixedResourceLocations.get(fileName);
		if (location == null) {
			return super.findResource(fileName);
		}
		String url;
		if (location instanceof File) {
			url = "file:/" + FileSupport.convertToUnixStylePath(((File) location).getAbsolutePath());
		} else {
			url = "jar:file:" + FileSupport.convertToUnixStylePath((String) location) + "!/" + fileName;
		}
		try {
			return new URL(url);
		} catch (MalformedURLException e) {
			throw new ResourceException(e);
		}
	}
1293938
private final void readDirectories(final URL jarFile) {
		JarInputStream jarIn = null;

		try {
			if (!jarFile.getPath().endsWith(".jar")) {
				return;
			}
			if (CClassLoader.sl(CClassLoader.DEBUG)) {
				CClassLoader.log("opening jar : " + jarFile.toExternalForm(),
						CClassLoader.DEBUG);
			}
			jarIn = new JarInputStream(jarFile.openStream());
			JarEntry jarEntry = null;

			while ((jarEntry = jarIn.getNextJarEntry()) != null) {
				if (jarEntry.isDirectory()) {
					continue;
				}

				final URL url = new URL("yahpjarloader://"
						+ CBASE64Codec.encode(
								jarFile.toExternalForm().getBytes("utf-8"))
								.replaceAll("\n", "") + "/"
						+ jarEntry.getName());

				if (CClassLoader.sl(CClassLoader.DEBUG)) {
					CClassLoader.log("found entry : " + url.toString(),
							CClassLoader.DEBUG);
				}

				if (jarEntry.getName().endsWith(".class")) {
					if (!this.classesMap.containsKey(jarEntry.getName())) {
						if (!this.booResourceOnly) {
							this.classesMap.put(jarEntry.getName(), url);
						}
					}

					if (this.resourcesMap.containsKey(jarEntry.getName())) {
						final Object to = this.resourcesMap.get(jarEntry
								.getName());
						if (to instanceof URL) {
							final URL uo = (URL) to;
							final List l = new ArrayList();
							l.add(uo);
							l.add(url);
							this.resourcesMap.put(jarEntry.getName(), l);
						} else if (to instanceof List) {
							final List uo = (List) to;
							uo.add(url);
							this.resourcesMap.put(jarEntry.getName(), uo);
						}
					} else {
						this.resourcesMap.put(jarEntry.getName(), url);
					}
				} else if (jarEntry.getName().startsWith("native/")) {
					String system = jarEntry.getName().substring(7);
					system = system.substring(0, system.indexOf('/'));
					if (!this.dllMap.containsKey(system)) {
						this.dllMap.put(system, url);
					}
					if (this.resourcesMap.containsKey(jarEntry.getName())) {
						final Object to = this.resourcesMap.get(jarEntry
								.getName());
						if (to instanceof URL) {
							final URL uo = (URL) to;
							final List l = new ArrayList();
							l.add(uo);
							l.add(url);
							this.resourcesMap.put(jarEntry.getName(), l);
						} else if (to instanceof List) {
							final List uo = (List) to;
							uo.add(url);
							this.resourcesMap.put(jarEntry.getName(), uo);
						}
					} else {
						this.resourcesMap.put(jarEntry.getName(), url);
					}
				} else {
					if (this.resourcesMap.containsKey(jarEntry.getName())) {
						final Object to = this.resourcesMap.get(jarEntry
								.getName());
						if (to instanceof URL) {
							final URL uo = (URL) to;
							final List l = new ArrayList();
							l.add(uo);
							l.add(url);
							this.resourcesMap.put(jarEntry.getName(), l);
						} else if (to instanceof List) {
							final List uo = (List) to;
							uo.add(url);
							this.resourcesMap.put(jarEntry.getName(), uo);
						}
					} else {
						this.resourcesMap.put(jarEntry.getName(), url);
					}
				}
			}

			if (CClassLoader.sl(CClassLoader.DEBUG)) {
				CClassLoader.log("opening jar : "
						+ jarFile.getFile().toString() + " done.",
						CClassLoader.DEBUG);
			}
		} catch (final MalformedURLException mue) {
			mue.printStackTrace();

			if (CClassLoader.sl(CClassLoader.FATAL)) {
				CClassLoader.log(mue.getMessage(), CClassLoader.FATAL);
			}
		} catch (final IOException ioe) {
			ioe.printStackTrace();

			if (CClassLoader.sl(CClassLoader.FATAL)) {
				CClassLoader.log(ioe.getMessage(), CClassLoader.FATAL);
			}
		} catch (final Exception e) {
			e.printStackTrace();

			if (CClassLoader.sl(CClassLoader.FATAL)) {
				CClassLoader.log(e.getMessage(), CClassLoader.FATAL);
			}
		} finally {
			try {
				jarIn.close();
				jarIn = null;
			} catch (final Exception e) {
			}
		}
	}