當前位置: 首頁>>代碼示例>>Java>>正文


Java URL.getHost方法代碼示例

本文整理匯總了Java中java.net.URL.getHost方法的典型用法代碼示例。如果您正苦於以下問題:Java URL.getHost方法的具體用法?Java URL.getHost怎麽用?Java URL.getHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getHost方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHostName

import java.net.URL; //導入方法依賴的package包/類
/**
 * Gets the host name from the repositoryURL
 * 
 * @return The host name. An empty string if not connected. Never <code>null</code>.
 */
public String getHostName() {
	if (git != null) {
		Config storedConfig = git.getRepository().getConfig();
		// TODO How we should react when there are multiple remote repositories???
		String url = storedConfig.getString("remote", "origin", "url");
		if (url == null) {
		  Set<String> remoteNames = git.getRepository().getRemoteNames();
		  url = storedConfig.getString("remote", remoteNames.iterator().next(), "url");
		}
		try {
			URL u = new URL(url);
			url = u.getHost();
			return url;
		} catch (MalformedURLException e) {
			return "";
		}
	}
	return "";

}
 
開發者ID:oxygenxml,項目名稱:oxygen-git-plugin,代碼行數:26,代碼來源:GitAccess.java

示例2: FtpURLConnection

import java.net.URL; //導入方法依賴的package包/類
/**
 * Same as FtpURLconnection(URL) with a per connection proxy specified
 */
FtpURLConnection(URL url, Proxy p) {
    super(url);
    instProxy = p;
    host = url.getHost();
    port = url.getPort();
    String userInfo = url.getUserInfo();

    if (userInfo != null) { // get the user and password
        int delimiter = userInfo.indexOf(':');
        if (delimiter == -1) {
            user = ParseUtil.decode(userInfo);
            password = null;
        } else {
            user = ParseUtil.decode(userInfo.substring(0, delimiter++));
            password = ParseUtil.decode(userInfo.substring(delimiter));
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:FtpURLConnection.java

示例3: updateMediaNotificationForTab

import java.net.URL; //導入方法依賴的package包/類
/**
 * Send an intent to MediaCaptureNotificationService to either create, update or destroy the
 * notification identified by tabId.
 * @param tabId Unique notification id.
 * @param mediaType The media type that is being captured.
 * @param fullUrl Url of the current webrtc call.
 */
public static void updateMediaNotificationForTab(
        Context context, int tabId, int mediaType, String fullUrl) {
    if (!shouldStartService(context, mediaType, tabId)) return;
    Intent intent = new Intent(context, MediaCaptureNotificationService.class);
    intent.setAction(ACTION_MEDIA_CAPTURE_UPDATE);
    intent.putExtra(NOTIFICATION_ID_EXTRA, tabId);
    String baseUrl = fullUrl;
    try {
        URL url = new URL(fullUrl);
        baseUrl = url.getProtocol() + "://" + url.getHost();
    } catch (MalformedURLException e) {
        Log.w(TAG, "Error parsing the webrtc url, %s ", fullUrl);
    }
    intent.putExtra(NOTIFICATION_MEDIA_URL_EXTRA, baseUrl);
    intent.putExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, mediaType);
    context.startService(intent);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:25,代碼來源:MediaCaptureNotificationService.java

示例4: openConnection

import java.net.URL; //導入方法依賴的package包/類
@Override
public HttpClientConnection openConnection(URL url) throws IOException {
    Socket socket = "https".equalsIgnoreCase(url.getProtocol())
            ? SSLSocketFactory.getDefault().createSocket(url.getHost(), url.getPort() > 0 ? url.getPort() : 443)
            : new Socket(url.getHost(), url.getPort() > 0 ? url.getPort() : 80);

    return DefaultBHttpClientConnectionFactory.INSTANCE.createConnection(socket);
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:9,代碼來源:DefaultHttpClientConnectionFactory.java

示例5: init

import java.net.URL; //導入方法依賴的package包/類
private void init(
	String modelURL
) {
	try 
	{
		URL url = new URL( modelURL );
		String hostName = url.getHost(); 
		if( hostName.equalsIgnoreCase( BIMViewer.HOST_PARAM_MARKER ) )
		{
			hostName = getModelHostname();
			_modelURL = url.getProtocol() + "://" + getModelHostname() + url.getPath();
		}
		else
		{
			_modelURL = modelURL;
		}
	} 
	catch (MalformedURLException e) 
	{
		_modelURL = modelURL;
	}

	if( _attribClass == null ) _attribClass = "LcRevitData";
	if( _attribName == null )  _attribName  = "Element";
	if( _paramClass == null )  _paramClass  = "LcRevitData";
	if( _paramName == null )   _paramName   = "Guid";
}
 
開發者ID:IBM,項目名稱:MaximoForgeViewerPlugin,代碼行數:28,代碼來源:BIMModelSpec.java

示例6: getFileSystem

import java.net.URL; //導入方法依賴的package包/類
@Nullable
public JavaFileManager getFileSystem(URL url) {
    String prefix = url.getProtocol() + "://" + url.getHost() + "/";
    if(prefix2jfm.containsKey(prefix)) {
        return prefix2jfm.get(prefix).get();
    } else {
        return null;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:FileSystemRegistry.java

示例7: setURL

import java.net.URL; //導入方法依賴的package包/類
/**
* Sets new URL.
*
* @param url URL to show in this browser.
*/
public void setURL(final URL url) {
    if (url == null) {
        txtLocation.setText(null);
        return;
    }

    class URLSetter implements Runnable {
        private boolean doReload = false;

        @Override
        public void run() {
            if (!SwingUtilities.isEventDispatchThread()) {
                boolean sameHosts = false;
                if ("nbfs".equals(url.getProtocol())) { // NOI18N
                    sameHosts = true;
                } else {
                    sameHosts = (url.getHost() != null) && (browserImpl.getURL() != null) &&
                        (url.getHost().equals(browserImpl.getURL().getHost()));
                }
                doReload = sameHosts && url.equals(browserImpl.getURL()); // see bug 9470

                SwingUtilities.invokeLater(this);
            } else {
                if (doReload) {
                    browserImpl.reloadDocument();
                } else {
                    browserImpl.setURL(url);
                }
            }
        }
    }
    rp.post(new URLSetter());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:HtmlBrowser.java

示例8: savePublishedEndpoint

import java.net.URL; //導入方法依賴的package包/類
public void savePublishedEndpoint(String protocol, String host, String port, String serviceSuffix) throws MalformedURLException {
    URL hostUrl = new URL(host);
    String endpointProtocol = HTTP_PROTOCOL;
    if (HTTPS_PROTOCOL.equalsIgnoreCase(protocol)) {
        endpointProtocol = HTTPS_PROTOCOL;
    }
    String webServiceEndpointUrl = endpointProtocol + "://" + hostUrl.getHost() + ":" + port + "/" + serviceSuffix;
    Thucydides.getCurrentSession().put(WEB_SERVICE_ENDPOINT_URL_KEY, webServiceEndpointUrl);
    LOGGER.info("Saved published endpoint URL is:" + webServiceEndpointUrl);
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:11,代碼來源:WebserviceSteps.java

示例9: getJsonURL

import java.net.URL; //導入方法依賴的package包/類
private URL getJsonURL(URL url) throws MalformedURLException {
    // Append ".json" to URL in appropriate location.
    String result = url.getProtocol() + "://" + url.getHost() + url.getPath() + ".json";
    if (url.getQuery() != null) {
        result += "?" + url.getQuery();
    }
    return new URL(result);
}
 
開發者ID:RipMeApp,項目名稱:ripme,代碼行數:9,代碼來源:RedditRipper.java

示例10: concatenateURL

import java.net.URL; //導入方法依賴的package包/類
/**
 * Concatenates the given {@link java.net.URL} and query.
 *
 * @param url   URL to base off
 * @param query Query to append to URL
 * @return URL constructed
 */
public static URL concatenateURL(final URL url, final String query) {
    try {
        if (url.getQuery() != null && url.getQuery().length() > 0) {
            return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "&" + query);
        } else {
            return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "?" + query);
        }
    } catch (final MalformedURLException ex) {
        throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
    }
}
 
開發者ID:CyR1en,項目名稱:Minecordbot,代碼行數:19,代碼來源:HTTPUtils.java

示例11: hostsEqual

import java.net.URL; //導入方法依賴的package包/類
@Override
protected boolean hostsEqual(URL u1, URL u2) {
    final String host1 = u1.getHost();
    final String host2 = u2.getHost();
    
    if (host1 != null && host2 != null)
        return host1.equalsIgnoreCase(host2);
     else
        return host1 == null && host2 == null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:NbinstURLStreamHandler.java

示例12: getScaledImageURL

import java.net.URL; //導入方法依賴的package包/類
private static URL getScaledImageURL(URL url) {
    try {
        String scaledImagePath = getScaledImageName(url.getPath());
        return scaledImagePath == null ? null : new URL(url.getProtocol(),
                url.getHost(), url.getPort(), scaledImagePath);
    } catch (MalformedURLException e) {
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:LWCToolkit.java

示例13: getInputStream

import java.net.URL; //導入方法依賴的package包/類
private InputStream getInputStream(URL url) throws IOException {
    if ("file".equalsIgnoreCase(url.getProtocol())) {
        // Compatibility notes:
        //
        // Code changed from
        //   String path = url.getFile().replace('/', File.separatorChar);
        //   return new FileInputStream(path);
        //
        // The original implementation would search for "/tmp/a%20b"
        // when url is "file:///tmp/a%20b". This is incorrect. The
        // current codes fix this bug and searches for "/tmp/a b".
        // For compatibility reasons, when the file "/tmp/a b" does
        // not exist, the file named "/tmp/a%20b" will be tried.
        //
        // This also means that if both file exists, the behavior of
        // this method is changed, and the current codes choose the
        // correct one.
        try {
            return url.openStream();
        } catch (Exception e) {
            String file = url.getPath();
            if (url.getHost().length() > 0) {  // For Windows UNC
                file = "//" + url.getHost() + file;
            }
            if (debugConfig != null) {
                debugConfig.println("cannot read " + url +
                                    ", try " + file);
            }
            return new FileInputStream(file);
        }
    } else {
        return url.openStream();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:ConfigFile.java

示例14: buildNewURL

import java.net.URL; //導入方法依賴的package包/類
private URL buildNewURL(URL base, String file) throws MalformedURLException {
    return new URL(base.getProtocol(), base.getHost(), file);
}
 
開發者ID:MyCoRe-Org,項目名稱:solr-runner-maven-plugin,代碼行數:4,代碼來源:AbstractSolrMojo.java

示例15: BIMModelSpec

import java.net.URL; //導入方法依賴的package包/類
BIMModelSpec(
       String    locationName,
       String    location,
       String    binding,
       MboRemote model
) 
	throws RemoteException, 
	       MXException 
{
	_locationName  = locationName;
	_location      = location;
	_binding       = binding;
	_modelId       = model.getLong(   FIELD_BUILDINGMODELID );
	setTitle( model.getString( BuildingModel.FIELD_TITLE ) );
	_description   = model.getString( BuildingModel.FIELD_DESCRIPTION );
	_assetView     = model.getString( BuildingModel.FIELD_ASSETVIEW );
	_lookupView    = model.getString( BuildingModel.FIELD_LOOKUPVIEW );
	_locationView  = model.getString( BuildingModel.FIELD_LOCATIONVIEW );
	_attribClass   = model.getString( BuildingModel.FIELD_ATTRIBUTECLASS );
	_attribName    = model.getString( BuildingModel.FIELD_ATTRIBUTENAME );
	_paramClass    = model.getString( BuildingModel.FIELD_PARAMCLASS );
	_paramName     = model.getString( BuildingModel.FIELD_PARAMNAME );
	_siteId        = model.getString( BuildingModel.FIELD_SITEID );
	_workOrderView = model.getString( BuildingModel.FIELD_WORKORDERVIEW );
	
	if( !model.getMboValueData( BuildingModel.FIELD_SELMODE ).isNull() )
	{
		try
		{
			_selectionMode = Integer.parseInt( model.getString( BuildingModel.FIELD_SELMODE ) );
		}
		catch( Throwable t )
		{ // Ignore  
		}
	}
	
	String modelURL = model.getString( BuildingModel.FIELD_URL );
	try 
	{
		URL url = new URL( modelURL );
		String hostName = url.getHost(); 
		if( hostName.equalsIgnoreCase( BIMViewer.HOST_PARAM_MARKER ) )
		{
			hostName = getModelHostname();
			_modelURL = url.getProtocol() + "://" + getModelHostname() + url.getPath();
		}
		else
		{
			_modelURL = modelURL;
		}
	} 
	catch (MalformedURLException e) 
	{
		_modelURL = modelURL;
	}

	if( _attribClass == null ) _attribClass = "LcRevitData";
	if( _attribName == null )  _attribName  = "Element";
	if( _paramClass == null )  _paramClass  = "LcRevitData";
	if( _paramName == null )   _paramName   = "Guid";
}
 
開發者ID:IBM,項目名稱:MaximoForgeViewerPlugin,代碼行數:62,代碼來源:BIMModelSpec.java


注:本文中的java.net.URL.getHost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。