java.net.URL#getDefaultPort ( )源码实例Demo

下面列出了java.net.URL#getDefaultPort ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-jdk   文件: AuthenticationInfo.java
public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
    this.type = type;
    this.authScheme = authScheme;
    this.protocol = url.getProtocol().toLowerCase();
    this.host = url.getHost().toLowerCase();
    this.port = url.getPort();
    if (this.port == -1) {
        this.port = url.getDefaultPort();
    }
    this.realm = realm;

    String urlPath = url.getPath();
    if (urlPath.length() == 0)
        this.path = urlPath;
    else {
        this.path = reducePath (urlPath);
    }

}
 
源代码2 项目: dragonwell8_jdk   文件: HttpCallerInfo.java
/**
 * Constructor an un-schemed object for site access.
 */
public HttpCallerInfo(URL url) {
    this.url= url;
    prompt = "";
    host = url.getHost();

    int p = url.getPort();
    if (p == -1) {
        port = url.getDefaultPort();
    } else {
        port = p;
    }

    InetAddress ia;
    try {
        ia = InetAddress.getByName(url.getHost());
    } catch (Exception e) {
        ia = null;
    }
    addr = ia;

    protocol = url.getProtocol();
    authType = RequestorType.SERVER;
    scheme = "";
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: AuthenticationInfo.java
public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) {
    this.type = type;
    this.authScheme = authScheme;
    this.protocol = url.getProtocol().toLowerCase();
    this.host = url.getHost().toLowerCase();
    this.port = url.getPort();
    if (this.port == -1) {
        this.port = url.getDefaultPort();
    }
    this.realm = realm;

    String urlPath = url.getPath();
    if (urlPath.length() == 0)
        this.path = urlPath;
    else {
        this.path = reducePath (urlPath);
    }

}
 
源代码4 项目: openjdk-jdk9   文件: HttpCallerInfo.java
/**
 * Constructor an un-schemed object for site access.
 */
public HttpCallerInfo(URL url, Authenticator a) {
    this.url= url;
    prompt = "";
    host = url.getHost();

    int p = url.getPort();
    if (p == -1) {
        port = url.getDefaultPort();
    } else {
        port = p;
    }

    InetAddress ia;
    try {
        ia = InetAddress.getByName(url.getHost());
    } catch (Exception e) {
        ia = null;
    }
    addr = ia;

    protocol = url.getProtocol();
    authType = RequestorType.SERVER;
    scheme = "";
    authenticator = a;
}
 
源代码5 项目: jdk8u-dev-jdk   文件: HttpCallerInfo.java
/**
 * Constructor an un-schemed object for site access.
 */
public HttpCallerInfo(URL url) {
    this.url= url;
    prompt = "";
    host = url.getHost();

    int p = url.getPort();
    if (p == -1) {
        port = url.getDefaultPort();
    } else {
        port = p;
    }

    InetAddress ia;
    try {
        ia = InetAddress.getByName(url.getHost());
    } catch (Exception e) {
        ia = null;
    }
    addr = ia;

    protocol = url.getProtocol();
    authType = RequestorType.SERVER;
    scheme = "";
}
 
源代码6 项目: Bytecoder   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码7 项目: hottub   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码8 项目: jdk8u-jdk   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码9 项目: dragonwell8_jdk   文件: AuthenticationInfo.java
/**
 * Returns info for the URL, for an HTTP server auth.  Used when we
 * don't yet know the realm
 * (i.e. when we're preemptively setting the auth).
 */
static AuthenticationInfo getServerAuth(URL url) {
    int port = url.getPort();
    if (port == -1) {
        port = url.getDefaultPort();
    }
    String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase()
            + ":" + url.getHost().toLowerCase() + ":" + port;
    return getAuth(key, url);
}
 
源代码10 项目: openjdk-jdk9   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码11 项目: TorrentEngine   文件: UPnPPluginService.java
public int
getPort()
{
	URL	url = connection.getGenericService().getDevice().getRootDevice().getLocation();
	
	int	port = url.getPort();
	
	if ( port == -1 ){
		
		port = url.getDefaultPort();
	}
	
	return( port );
}
 
源代码12 项目: galaxy-sdk-java   文件: TalosHttpClient.java
public TalosHttpClient(String url, HttpClient client, Credential credential, AdjustableClock clock)
    throws TTransportException {
  try {
    url_ = new URL(url);
    this.client = client;
    this.host = new HttpHost(url_.getHost(), -1 == url_.getPort() ? url_.getDefaultPort()
        : url_.getPort(), url_.getProtocol());
    this.credential = credential;
    this.clock = clock;
  } catch (IOException iox) {
    throw new TTransportException(iox);
  }
}
 
源代码13 项目: openjdk-8   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码14 项目: incubator-retired-blur   文件: THttpClient.java
public THttpClient(String url, HttpClient client) throws TTransportException {
  try {
    url_ = new URL(url);
    this.client = client;
    this.host = new HttpHost(url_.getHost(), -1 == url_.getPort() ? url_.getDefaultPort() : url_.getPort(), url_.getProtocol());
  } catch (IOException iox) {
    throw new TTransportException(iox);
  }
}
 
源代码15 项目: jdk8u60   文件: HttpURLConnection.java
static String connectRequestURI(URL url) {
    String host = url.getHost();
    int port = url.getPort();
    port = port != -1 ? port : url.getDefaultPort();

    return host + ":" + port;
}
 
源代码16 项目: TencentKona-8   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码18 项目: openjdk-8-source   文件: AuthenticationInfo.java
/**
 * Returns info for the URL, for an HTTP server auth.  Used when we
 * don't yet know the realm
 * (i.e. when we're preemptively setting the auth).
 */
static AuthenticationInfo getServerAuth(URL url) {
    int port = url.getPort();
    if (port == -1) {
        port = url.getDefaultPort();
    }
    String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase()
            + ":" + url.getHost().toLowerCase() + ":" + port;
    return getAuth(key, url);
}
 
源代码19 项目: jdk8u-jdk   文件: URLUtil.java
/**
 * Returns a string form of the url suitable for use as a key in HashMap/Sets.
 *
 * The string form should be behave in the same manner as the URL when
 * compared for equality in a HashMap/Set, except that no nameservice
 * lookup is done on the hostname (only string comparison), and the fragment
 * is not considered.
 *
 * @see java.net.URLStreamHandler.sameFile(java.net.URL)
 */
public static String urlNoFragString(URL url) {
    StringBuilder strForm = new StringBuilder();

    String protocol = url.getProtocol();
    if (protocol != null) {
        /* protocol is compared case-insensitive, so convert to lowercase */
        protocol = protocol.toLowerCase();
        strForm.append(protocol);
        strForm.append("://");
    }

    String host = url.getHost();
    if (host != null) {
        /* host is compared case-insensitive, so convert to lowercase */
        host = host.toLowerCase();
        strForm.append(host);

        int port = url.getPort();
        if (port == -1) {
            /* if no port is specificed then use the protocols
             * default, if there is one */
            port = url.getDefaultPort();
        }
        if (port != -1) {
            strForm.append(":").append(port);
        }
    }

    String file = url.getFile();
    if (file != null) {
        strForm.append(file);
    }

    return strForm.toString();
}
 
源代码20 项目: BiglyBT   文件: TorrentUtils.java
private static List<URL>
applyAllDNSMods(
	URL		url )
{
	List<URL> default_result = new ArrayList<>(1);
	
	default_result.add( url );
	
	if ( DNS_HANDLING_ENABLE ){

		DNSTXTEntry txt_entry = getDNSTXTEntry( url );

		if ( txt_entry != null && txt_entry.hasRecords()){		

			boolean url_is_tcp 	= url.getProtocol().toLowerCase().startsWith( "http" );
			int		url_port	= url.getPort();

			if ( url_port == -1 ){

				url_port = url.getDefaultPort();
			}

			List<DNSTXTPortInfo>	ports = txt_entry.getPorts();

			if ( ports.size() == 0 ){

				return( null );	// NULL here as no valid ports

			}else{

				List<URL>	result = new ArrayList<>();

				for ( DNSTXTPortInfo port: ports ){

					URL	mod_url = url;

					int target_port = port.getPort();
					
					if ( url_port != target_port ){

						mod_url = UrlUtils.setPort( mod_url, target_port==mod_url.getDefaultPort()?0:target_port );
					}

					if ( url_is_tcp != port.isTCP()){

						mod_url = UrlUtils.setProtocol( mod_url, port.isTCP()?"http":"udp" );
					}

					result.add( mod_url );
				}

				return( result );
			}
		}else{

			return( default_result );
		}
	}else{

		return( default_result );
	}
}