當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。