当前位置: 首页>>代码示例>>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;未经允许,请勿转载。