Java URL Value Check isJarURL(URL url)

Here you can find the source of isJarURL(URL url)

Description

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

License

LGPL

Parameter

Parameter Description
url the URL to check

Return

whether the URL has been identified as a JAR URL

Declaration

public static boolean isJarURL(URL url) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.net.URL;

public class Main {
    /** URL protocol for an entry from a jar file: "jar" */
    public static final String URL_PROTOCOL_JAR = "jar";
    /** URL protocol for an entry from a zip file: "zip" */
    public static final String URL_PROTOCOL_ZIP = "zip";
    /** URL protocol for an entry from a WebSphere jar file: "wsjar" */
    public static final String URL_PROTOCOL_WSJAR = "wsjar";
    /** URL protocol for an entry from an OC4J jar file: "code-source" */
    public static final String URL_PROTOCOL_CODE_SOURCE = "code-source";
    /** Separator between JAR URL and file path within the JAR */
    public static final String JAR_URL_SEPARATOR = "!/";

    /**/*  w  w  w  . j  av a2 s  .  c  o m*/
     * Determine whether the given URL points to a resource in a jar file,
     * that is, has protocol "jar", "zip", "wsjar" or "code-source".
     * <p>"zip" and "wsjar" are used by BEA WebLogic Server and IBM WebSphere, respectively,
     * but can be treated like jar files. The same applies to "code-source" URLs on Oracle
     * OC4J, provided that the path contains a jar separator.
     * @param url the URL to check
     * @return whether the URL has been identified as a JAR URL
     */
    public static boolean isJarURL(URL url) {
        String protocol = url.getProtocol();
        return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol)
                || URL_PROTOCOL_WSJAR.equals(protocol)
                || (URL_PROTOCOL_CODE_SOURCE.equals(protocol) && url.getPath().contains(JAR_URL_SEPARATOR)));
    }
}

Related

  1. isJar(URL url)
  2. isJarFile(URL url)
  3. isJarFile(URLConnection connection)
  4. isJarFileURL(URL url)
  5. isJarURL(URL url)
  6. isJarURL(URL url)
  7. isJarURL(URL url)
  8. isJarURL(URL url)
  9. isJarURL(URL url)