当前位置: 首页>>代码示例>>Java>>正文


Java URL.getDefaultPort方法代码示例

本文整理汇总了Java中java.net.URL.getDefaultPort方法的典型用法代码示例。如果您正苦于以下问题:Java URL.getDefaultPort方法的具体用法?Java URL.getDefaultPort怎么用?Java URL.getDefaultPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getDefaultPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: HttpCallerInfo

import java.net.URL; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:HttpCallerInfo.java

示例2: isInstitutionUrl

import java.net.URL; //导入方法依赖的package包/类
@Override
public boolean isInstitutionUrl(String url)
{
	try
	{
		URL iUrl = getInstitutionUrl();
		URL myUrl = new URL(url);
		int myPort = myUrl.getPort();
		if( myPort == -1 )
		{
			myPort = myUrl.getDefaultPort();
		}
		int iPort = iUrl.getPort();
		if( iPort == -1 )
		{
			iPort = iUrl.getDefaultPort();
		}
		return (iUrl.getHost().equals(myUrl.getHost()) && (myPort == iPort)
				&& myUrl.getPath().startsWith(iUrl.getPath()));
	}
	catch( MalformedURLException e )
	{
		return false;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:26,代码来源:InstitutionServiceImpl.java

示例3: create

import java.net.URL; //导入方法依赖的package包/类
public static HttpClient<ByteBuf, ByteBuf> create(String server, final String portStr) {
    int port = 0;

    try {

        URL url = new URL(defaultToHttps(server));
        if (portStr == null) {
            port = url.getDefaultPort();
        } else if (Integer.parseInt(portStr) > 0){
            port = Integer.parseInt(portStr);
        }
        final HttpClient<ByteBuf, ByteBuf> httpClient = HttpClient.newClient(new InetSocketAddress(
                url.getHost(), port));
        if(url.getProtocol().equals("https")) {
            return httpClient.unsafeSecure();
        } else if (url.getProtocol().equals("http")) {
            return httpClient;
        } else {
            throw new RuntimeException("Unsuported protocol");
        }
    }

    catch(MalformedURLException e){
        throw new RuntimeException(e);
    }
}
 
开发者ID:gradle,项目名称:ge-export,代码行数:27,代码来源:HttpClientFactory.java

示例4: AuthenticationInfo

import java.net.URL; //导入方法依赖的package包/类
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);
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:AuthenticationInfo.java

示例5: HttpCallerInfo

import java.net.URL; //导入方法依赖的package包/类
/**
 * 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 = "";
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:HttpCallerInfo.java

示例6: AuthenticationInfo

import java.net.URL; //导入方法依赖的package包/类
public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm,
                          String authenticatorKey) {
    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);
    }
    this.authenticatorKey = Objects.requireNonNull(authenticatorKey);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:AuthenticationInfo.java

示例7: getServerAuthKey

import java.net.URL; //导入方法依赖的package包/类
/**
 * Returns info for the URL, for an HTTP server auth.  Used when we
 * do know the realm (i.e. when we're responding to a challenge).
 * In this case we do not use the path because the protection space
 * is identified by the host:port:realm only
 */
static String getServerAuthKey(URL url, String realm, AuthScheme scheme,
                               String authenticatorKey) {
    int port = url.getPort();
    if (port == -1) {
        port = url.getDefaultPort();
    }
    String key = SERVER_AUTHENTICATION + ":" + scheme + ":"
                 + url.getProtocol().toLowerCase()
                 + ":" + url.getHost().toLowerCase()
                 + ":" + port + ":" + realm
                 + ";auth=" + authenticatorKey;
    return key;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:AuthenticationInfo.java

示例8: getServerAuthKey

import java.net.URL; //导入方法依赖的package包/类
/**
 * Returns info for the URL, for an HTTP server auth.  Used when we
 * do know the realm (i.e. when we're responding to a challenge).
 * In this case we do not use the path because the protection space
 * is identified by the host:port:realm only
 */
static String getServerAuthKey(URL url, String realm, AuthScheme scheme) {
    int port = url.getPort();
    if (port == -1) {
        port = url.getDefaultPort();
    }
    String key = SERVER_AUTHENTICATION + ":" + scheme + ":" + url.getProtocol().toLowerCase()
                 + ":" + url.getHost().toLowerCase() + ":" + port + ":" + realm;
    return key;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:AuthenticationInfo.java

示例9: connectRequestURI

import java.net.URL; //导入方法依赖的package包/类
static String connectRequestURI(URL url) {
    String host = url.getHost();
    int port = url.getPort();
    port = port != -1 ? port : url.getDefaultPort();

    return host + ":" + port;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:HttpURLConnection.java

示例10: urlNoFragString

import java.net.URL; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:URLUtil.java

示例11: getServerPort

import java.net.URL; //导入方法依赖的package包/类
public int
getServerPort()
{
	if ( tracker_context == null ){

		return( 0 );
	}

	URL	url = tracker_context.getURLs()[0];

	return( url.getPort()==-1?url.getDefaultPort():url.getPort());
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:13,代码来源:WebPlugin.java

示例12: getServerAuth

import java.net.URL; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:AuthenticationInfo.java

示例13: getPort

import java.net.URL; //导入方法依赖的package包/类
public int
getPort()
{
	URL	url = connection.getGenericService().getDevice().getRootDevice().getLocation();

	int	port = url.getPort();

	if ( port == -1 ){

		port = url.getDefaultPort();
	}

	return( port );
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:15,代码来源:UPnPPluginService.java

示例14: getServerAuth

import java.net.URL; //导入方法依赖的package包/类
/**
 * 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, String authenticatorKey) {
    int port = url.getPort();
    if (port == -1) {
        port = url.getDefaultPort();
    }
    String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase()
            + ":" + url.getHost().toLowerCase() + ":" + port
            + ";auth=" + authenticatorKey;
    return getAuth(key, url);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:AuthenticationInfo.java

示例15: applyAllDNSMods

import java.net.URL; //导入方法依赖的package包/类
private static List<URL>
applyAllDNSMods(
	URL		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 );

			}else{

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

				for ( DNSTXTPortInfo port: ports ){

					URL	mod_url = url;

					if ( url_port != port.getPort()){

						mod_url = UrlUtils.setPort( mod_url, port.getPort());
					}

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

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

					result.add( mod_url );
				}

				return( result );
			}
		}else{

			return( null );
		}
	}else{

		return( null );
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:57,代码来源:TorrentUtils.java


注:本文中的java.net.URL.getDefaultPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。