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


Java URL.toString方法代碼示例

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


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

示例1: get

import java.net.URL; //導入方法依賴的package包/類
@Override
public HttpResponse get(URL urlObj, String userName, String password, int timeout) {
  HttpClient client = new HttpClient();
  HttpMethod method = new GetMethod(urlObj.toString());

  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to get " + urlObj.toString(), e);
  } finally {
    method.releaseConnection();
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:22,代碼來源:LogiURLFetchService.java

示例2: main

import java.net.URL; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    String uri1 = "http://h/../d1/";
    String uri2 = "../d/i.htm";
    String expected = "http://h/../d/i.htm";

    URI uri = new URI(uri1);
    String s1 = uri.resolve(uri2).toString();
    URL url = new URL(uri1);
    URL url2 = new URL(url, uri2);
    String s2 = url2.toString();
    if (!(expected.equalsIgnoreCase(s1)))
        throw new RuntimeException("URI.resolve didn't return expected result [" + s1 + " versus " + expected + "]");
    if (!(expected.equalsIgnoreCase(s2)))
        throw new RuntimeException("URL(url, String) didn't return expected result [" + s2 + " versus " + expected + "]");

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:RelativePath.java

示例3: printableURL

import java.net.URL; //導入方法依賴的package包/類
/**
 * <p>Compute the printable representation of a URL, leaving off the
 * scheme/host/port part if no host is specified. This will typically
 * be the case for URLs that were originally created from relative
 * or context-relative URIs.</p>
 *
 * @param url URL to render in a printable representation
 * @return printable representation of a URL
 */
public static String printableURL(URL url) {

    if (url.getHost() != null) {
        return (url.toString());
    }

    String file = url.getFile();
    String ref = url.getRef();
    if (ref == null) {
        return (file);
    } else {
        StringBuffer sb = new StringBuffer(file);
        sb.append('#');
        sb.append(ref);
        return (sb.toString());
    }

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:RequestUtils.java

示例4: getPrettyFileUrl

import java.net.URL; //導入方法依賴的package包/類
public static String getPrettyFileUrl(URL url) {
	try {
		String result = URLDecoder.decode(url.toString(), "UTF-8");
		if (result.startsWith("file:/")) {
			result = result.substring(6);
		}
		if (result.startsWith("jndi:/")) {
			result = result.substring(6);
		}
		result = result.replace("/", File.separator).replace("\\", File.separator);
		return result;
	} catch (UnsupportedEncodingException e) {
		// Cannot happen, UTF-8 is always available
	}
	return url.toString();
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:17,代碼來源:StringUtils.java

示例5: getInputStream

import java.net.URL; //導入方法依賴的package包/類
/**
 * @deprecated Unused - will be removed in Tomcat 8.0.x
 */
@Deprecated
protected InputStream getInputStream() throws IOException {
    if( source instanceof URL ) {
        URL url=(URL)source;
        location=url.toString();
        return url.openStream();
    } else if( source instanceof File ) {
        location=((File)source).getAbsolutePath();
        return new FileInputStream((File)source);            
    } else if( source instanceof String) {
        location=(String)source;
        return new FileInputStream((String)source);            
    } else if( source instanceof InputStream ) {
        return (InputStream)source;
    } 
    return null;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:21,代碼來源:ModelerSource.java

示例6: get

import java.net.URL; //導入方法依賴的package包/類
JarFile get(URL url, boolean useCaches) throws IOException {

        JarFile result;
        JarFile local_result;

        if (useCaches) {
            synchronized (instance) {
                result = getCachedJarFile(url);
            }
            if (result == null) {
                local_result = URLJarFile.getJarFile(url, this);
                synchronized (instance) {
                    result = getCachedJarFile(url);
                    if (result == null) {
                        fileCache.put(URLUtil.urlNoFragString(url), local_result);
                        urlCache.put(local_result, url);
                        result = local_result;
                    } else {
                        if (local_result != null) {
                            local_result.close();
                        }
                    }
                }
            }
        } else {
            result = URLJarFile.getJarFile(url, this);
        }
        if (result == null)
            throw new FileNotFoundException(url.toString());

        return result;
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:33,代碼來源:JarFileFactory.java

示例7: load

import java.net.URL; //導入方法依賴的package包/類
public JsonNode load(URL url) throws IOException {
	String urlString = url.toString();
	if (cache.containsKey(urlString)) {
		return cache.get(urlString);
	}
	String json = NioUtils.toString(url.openStream());
	return loadString(url, json);
}
 
開發者ID:networknt,項目名稱:openapi-parser,代碼行數:9,代碼來源:JsonLoader.java

示例8: getImageWithResolutionVariant

import java.net.URL; //導入方法依賴的package包/類
protected Image getImageWithResolutionVariant(URL url,
        URL resolutionVariantURL) {
    synchronized (urlImgCache) {
        Image image = getImageFromHash(this, url);
        if (image instanceof MultiResolutionImage) {
            return image;
        }
        Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
        image = createImageWithResolutionVariant(image, resolutionVariant);
        String key = url.toString();
        urlImgCache.put(key, image);
        return image;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:SunToolkit.java

示例9: doDelete

import java.net.URL; //導入方法依賴的package包/類
@Override
public Response doDelete(final URL url, final Set<RequestHeader> headers) throws IOException {
    final HttpDelete request = new HttpDelete(url.toString());
    for(RequestHeader header : headers) {
        if(header.getKey().equals(HTTP.TRANSFER_ENCODING)) {
            continue;
        }
        if(header.getKey().equals(HTTP.CONTENT_LEN)) {
            continue;
        }
        request.addHeader(new BasicHeader(header.getKey(), header.getValue()));
    }
    final CloseableHttpResponse response = client.execute(request);
    return new CommonsHttpResponse(response);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:16,代碼來源:OneDriveCommonsHttpRequestExecutor.java

示例10: updateClassPath

import java.net.URL; //導入方法依賴的package包/類
private String [] updateClassPath (ILaunchConfiguration configuration) throws CoreException {
	URL resource  = this.getClass().getResource(GW4ELaunchConfigurationDelegate.class.getSimpleName() + ".class");

	String jarpath = GW4ELaunchConfigurationDelegate.class.getProtectionDomain().getCodeSource().getLocation().getPath ();
	 
	try {
		resource = FileLocator.toFileURL(resource);
	} catch (IOException e) {
		ResourceManager.logException(e);
	}
	
	String root = resource.toString();
	 
	if (root.startsWith("jar:")) {
	     String vals[] = root.split("/");
	     for (String val: vals) {
	       if (val.contains("!")) {
	    	   root = val.substring(0, val.length() - 1);
	       }
	     }
	} else {
		int pos = root.indexOf((GW4ELaunchConfigurationDelegate.class.getName() ).replaceAll("\\.", "/"));
		root = root.substring(0,pos);
	}
	 
	String[] defaultCp = getClasspath(configuration);
	String[] extendedCp = new String[defaultCp.length+2];
	System.arraycopy(defaultCp, 0, extendedCp, 0, defaultCp.length);
	extendedCp[extendedCp.length-1] = normalizePath(root);
	extendedCp[extendedCp.length-2] = normalizePath(jarpath);
	return extendedCp;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:33,代碼來源:GW4ELaunchConfigurationDelegate.java

示例11: massageURL

import java.net.URL; //導入方法依賴的package包/類
private static String massageURL(final URL url) {
    if (url == null) {
        return "<null>";
    }
    final String str = url.toString();
    final int slash = str.lastIndexOf('/');
    if (slash == -1) {
        return str;
    }
    return str.substring(slash + 1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ApplySpecialization.java

示例12: getWebAppsPath

import java.net.URL; //導入方法依賴的package包/類
/**
 * Get the pathname to the webapps files.
 * @param appName eg "secondary" or "datanode"
 * @return the pathname as a URL
 * @throws FileNotFoundException if 'webapps' directory cannot be found on CLASSPATH.
 */
protected String getWebAppsPath(String webapps, String appName) throws FileNotFoundException {
  URL url = getClass().getClassLoader().getResource(webapps + "/" + appName);
  if (url == null)
    throw new FileNotFoundException(webapps + "/" + appName
        + " not found in CLASSPATH");
  String urlString = url.toString();
  return urlString.substring(0, urlString.lastIndexOf('/'));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:HttpServer.java

示例13: getLocation

import java.net.URL; //導入方法依賴的package包/類
private static URL getLocation(Class<?> c) {
    if (c == null) {
        return null;
    }

    try {
        URL codeSourceLocation = c.getProtectionDomain().getCodeSource().getLocation();
        if (codeSourceLocation != null) {
            return codeSourceLocation;
        }
    } catch (SecurityException | NullPointerException ignored) {
    }
    URL classResource = c.getResource(c.getSimpleName() + ".class");
    if (classResource == null) {
        return null;
    }

    String url = classResource.toString();
    String suffix = c.getCanonicalName().replace('.', '/') + ".class";
    if (!url.endsWith(suffix)) {
        return null;
    }

    String path = url.substring(0, url.length() - suffix.length());
    if (path.startsWith("jar:")) {
        path = path.substring(4, path.length() - 2);
    }

    try {
        return new URL(path);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:MinecraftMarket,項目名稱:MinecraftMarket-Plugin,代碼行數:36,代碼來源:FileUtils.java

示例14: doGet

import java.net.URL; //導入方法依賴的package包/類
@Override
public Response doGet(final URL url, final Set<RequestHeader> headers) throws IOException {
    final HttpGet request = new HttpGet(url.toString());
    for(RequestHeader header : headers) {
        if(header.getKey().equals(HTTP.TRANSFER_ENCODING)) {
            continue;
        }
        if(header.getKey().equals(HTTP.CONTENT_LEN)) {
            continue;
        }
        request.addHeader(new BasicHeader(header.getKey(), header.getValue()));
    }
    final CloseableHttpResponse response = client.execute(request);
    return new CommonsHttpResponse(response);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:16,代碼來源:OneDriveCommonsHttpRequestExecutor.java

示例15: getLocation

import java.net.URL; //導入方法依賴的package包/類
public static String getLocation( Task t ) {
    URL url = getURL(t);
    if( null != url ) {
        return url.toString();
    }
    FileObject fo = getFile(t);
    String location = fo.getPath();
    int line = getLine(t);
    if( line >= 0 )
        location += ":" + line;
    return location;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:Accessor.java


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