类 URL

  • 所有已实现的接口:
    Serializable

    public final class URL
    extends Object
    implements Serializable
    URL - Uniform Resource Locator (Immutable, ThreadSafe)

    url example:

    • http://www.facebook.com/friends?param1=value1&param2=value2
    • http://username:password@10.20.130.230:8080/list?version=1.0.0
    • ftp://username:password@192.168.1.7:21/1/read.txt
    • registry://192.168.1.7:9090/com.alibaba.service1?param1=value1&param2=value2

    Some strange example below:

    • 192.168.1.3:20880
      for this case, url protocol = null, url host = 192.168.1.3, port = 20880, url path = null
    • file:///home/user1/router.js?type=script
      for this case, url protocol = file, url host = null, url path = home/user1/router.js
    • file://home/user1/router.js?type=script
      for this case, url protocol = file, url host = home, url path = user1/router.js
    • file:///D:/1/router.js?type=script
      for this case, url protocol = file, url host = null, url path = D:/1/router.js
    • file:/D:/1/router.js?type=script
      same as above file:///D:/1/router.js?type=script
    • /home/user1/router.js?type=script
      for this case, url protocol = null, url host = null, url path = home/user1/router.js
    • home/user1/router.js?type=script
      for this case, url protocol = null, url host = home, url path = user1/router.js
    另请参阅:
    URL, URI, 序列化表格
    • 方法详细资料

      • valueOf

        public static URL valueOf(String url)
        Parse url string
        参数:
        url - URL string
        返回:
        URL instance
        另请参阅:
        URL
      • getProtocol

        public String getProtocol()
      • setProtocol

        public URL setProtocol(String protocol)
      • getUsername

        public String getUsername()
      • setUsername

        public URL setUsername(String username)
      • getPassword

        public String getPassword()
      • setPassword

        public URL setPassword(String password)
      • getAuthority

        public String getAuthority()
      • getHost

        public String getHost()
      • getIp

        public String getIp()
        Fetch IP address for this URL. Pls. note that IP should be used instead of Host when to compare with socket's address or to search in a map which use address as its key.
        返回:
        ip in string format
      • getPort

        public int getPort()
      • setPort

        public URL setPort(int port)
      • getPort

        public int getPort(int defaultPort)
      • getAddress

        public String getAddress()
      • setAddress

        public URL setAddress(String address)
      • getBackupAddress

        public String getBackupAddress()
      • getBackupAddress

        public String getBackupAddress(int defaultPort)
      • getBackupUrls

        public List<URL> getBackupUrls()
      • getPath

        public String getPath()
      • getAbsolutePath

        public String getAbsolutePath()
      • getParameterAndDecoded

        public String getParameterAndDecoded(String key)
      • getParameterAndDecoded

        public String getParameterAndDecoded(String key,
                                             String defaultValue)
      • getUrlParameter

        public URL getUrlParameter(String key)
      • getParameter

        public double getParameter(String key,
                                   double defaultValue)
      • getParameter

        public float getParameter(String key,
                                  float defaultValue)
      • getParameter

        public long getParameter(String key,
                                 long defaultValue)
      • getParameter

        public int getParameter(String key,
                                int defaultValue)
      • getParameter

        public short getParameter(String key,
                                  short defaultValue)
      • getParameter

        public byte getParameter(String key,
                                 byte defaultValue)
      • getPositiveParameter

        public float getPositiveParameter(String key,
                                          float defaultValue)
      • getPositiveParameter

        public double getPositiveParameter(String key,
                                           double defaultValue)
      • getPositiveParameter

        public long getPositiveParameter(String key,
                                         long defaultValue)
      • getPositiveParameter

        public int getPositiveParameter(String key,
                                        int defaultValue)
      • getPositiveParameter

        public short getPositiveParameter(String key,
                                          short defaultValue)
      • getPositiveParameter

        public byte getPositiveParameter(String key,
                                         byte defaultValue)
      • getParameter

        public char getParameter(String key,
                                 char defaultValue)
      • getParameter

        public boolean getParameter(String key,
                                    boolean defaultValue)
      • hasParameter

        public boolean hasParameter(String key)
      • getMethodParameterAndDecoded

        public String getMethodParameterAndDecoded(String method,
                                                   String key)
      • getMethodParameterAndDecoded

        public String getMethodParameterAndDecoded(String method,
                                                   String key,
                                                   String defaultValue)
      • getMethodParameter

        public double getMethodParameter(String method,
                                         String key,
                                         double defaultValue)
      • getMethodParameter

        public float getMethodParameter(String method,
                                        String key,
                                        float defaultValue)
      • getMethodParameter

        public long getMethodParameter(String method,
                                       String key,
                                       long defaultValue)
      • getMethodParameter

        public int getMethodParameter(String method,
                                      String key,
                                      int defaultValue)
      • getMethodParameter

        public short getMethodParameter(String method,
                                        String key,
                                        short defaultValue)
      • getMethodParameter

        public byte getMethodParameter(String method,
                                       String key,
                                       byte defaultValue)
      • getMethodPositiveParameter

        public double getMethodPositiveParameter(String method,
                                                 String key,
                                                 double defaultValue)
      • getMethodPositiveParameter

        public float getMethodPositiveParameter(String method,
                                                String key,
                                                float defaultValue)
      • getMethodPositiveParameter

        public long getMethodPositiveParameter(String method,
                                               String key,
                                               long defaultValue)
      • getMethodPositiveParameter

        public int getMethodPositiveParameter(String method,
                                              String key,
                                              int defaultValue)
      • getMethodPositiveParameter

        public short getMethodPositiveParameter(String method,
                                                String key,
                                                short defaultValue)
      • getMethodPositiveParameter

        public byte getMethodPositiveParameter(String method,
                                               String key,
                                               byte defaultValue)
      • getMethodParameter

        public char getMethodParameter(String method,
                                       String key,
                                       char defaultValue)
      • getMethodParameter

        public boolean getMethodParameter(String method,
                                          String key,
                                          boolean defaultValue)
      • hasMethodParameter

        public boolean hasMethodParameter(String method,
                                          String key)
      • isLocalHost

        public boolean isLocalHost()
      • isAnyHost

        public boolean isAnyHost()
      • addParameterAndEncoded

        public URL addParameterAndEncoded(String key,
                                          String value)
      • addParameter

        public URL addParameter(String key,
                                boolean value)
      • addParameter

        public URL addParameter(String key,
                                char value)
      • addParameter

        public URL addParameter(String key,
                                byte value)
      • addParameter

        public URL addParameter(String key,
                                short value)
      • addParameter

        public URL addParameter(String key,
                                int value)
      • addParameter

        public URL addParameter(String key,
                                long value)
      • addParameter

        public URL addParameter(String key,
                                float value)
      • addParameter

        public URL addParameter(String key,
                                double value)
      • addParameter

        public URL addParameter(String key,
                                Enum<?> value)
      • addParameterIfAbsent

        public URL addParameterIfAbsent(String key,
                                        String value)
      • addParameters

        public URL addParameters(Map<String,String> parameters)
        Add parameters to a new url.
        参数:
        parameters - parameters in key-value pairs
        返回:
        A new URL
      • addParametersIfAbsent

        public URL addParametersIfAbsent(Map<String,String> parameters)
      • addParameters

        public URL addParameters(String... pairs)
      • addParameterString

        public URL addParameterString(String query)
      • removeParameter

        public URL removeParameter(String key)
      • removeParameters

        public URL removeParameters(String... keys)
      • clearParameters

        public URL clearParameters()
      • getRawParameter

        public String getRawParameter(String key)
      • toIdentityString

        public String toIdentityString()
      • toIdentityString

        public String toIdentityString(String... parameters)
      • toFullString

        public String toFullString()
      • toFullString

        public String toFullString(String... parameters)
      • toParameterString

        public String toParameterString()
      • toParameterString

        public String toParameterString(String... parameters)
      • toJavaURL

        public URL toJavaURL()
      • getServiceKey

        public String getServiceKey()
      • toServiceStringWithoutResolving

        public String toServiceStringWithoutResolving()
      • toServiceString

        public String toServiceString()
      • getServiceInterface

        public String getServiceInterface()
      • setServiceInterface

        public URL setServiceInterface(String service)
      • hashCode

        public int hashCode()
        覆盖:
        hashCode 在类中 Object