本文整理汇总了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;
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
示例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 = "";
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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);
}
示例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 );
}
示例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);
}
示例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 );
}
}