List of usage examples for java.net URL getProtocol
public String getProtocol()
From source file:Main.java
static String zzb(String... strArr) { Builder builder = new Builder(); int length = strArr.length; int i = 0;/* w w w .j av a 2s. c o m*/ while (i < length) { String str = strArr[i]; try { URL url = new URL(str); builder.appendQueryParameter("url", url.getProtocol() + "://" + url.getHost()); i++; } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL: " + str); } } return "weblogin:" + builder.build().getQuery(); }
From source file:Main.java
public static String encodeDocumentUrl(String urlString) { try {//from w w w . j a v a2 s . c om URL url = new URL(urlString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); return uri.toASCIIString(); } catch (MalformedURLException e) { return null; } catch (URISyntaxException e) { return null; } }
From source file:bad.robot.http.apache.Coercions.java
public static HttpHost asHttpHost(URL url) { return new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); }
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URI newEncodedURI(String u) throws MalformedURLException, URISyntaxException { URL tmpUrl = new URL(u); return new URI(tmpUrl.getProtocol(), tmpUrl.getUserInfo(), tmpUrl.getHost(), tmpUrl.getPort(), tmpUrl.getPath(), tmpUrl.getQuery(), tmpUrl.getRef()); }
From source file:com.threadswarm.imagefeedarchiver.FeedUtils.java
/** * Returns a hierarchical {@code URI} constructed from individual components * of the supplied {@code urlString} argument. * <p>//from w ww . j a v a 2s. c o m * The {@code urlString} argument is first used to instantiate a {@code URL} * which in turn is used to construct a {@code URI} based on the individual * components of the former. This more robust then simply calling {@code URL.toURI()}. * * @param urlString the {@code String} based representation of a URL * @return a {@code URI} constructed from the individual URL components * @throws URISyntaxException if a valid {@code URI} cannot be constructed from the supplied {@code urlString} argument * @throws MalformedURLException if the {@code urlString} cannot be used to instantiate a {@code URL} */ public static URI getUriFromUrlString(String urlString) throws URISyntaxException, MalformedURLException { URL url = new URL(urlString); return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); }
From source file:org.jboss.jdf.stacks.StacksFactory.java
public static Stacks create(final StacksConfiguration stacksConfig) throws IOException { InputStream inputStream = null; HttpResponse response = null;//w ww . jav a 2 s .c o m DefaultHttpClient client = null; final URL url = stacksConfig.getUrl(); try { if (url.getProtocol().startsWith("file")) { inputStream = new FileInputStream(new File(url.toURI())); } else { client = new DefaultHttpClient(); configureProxy(client, stacksConfig); final HttpGet method = new HttpGet(url.toURI()); response = client.execute(method); final HttpEntity entity = response.getEntity(); if (entity != null) { inputStream = entity.getContent(); } } return new Parser().parse(inputStream); } catch (URISyntaxException e) { // TODO cleanup throw new IllegalStateException(e); } finally { HttpClientUtils.closeQuietly(response); HttpClientUtils.closeQuietly(client); Parser.safeClose(inputStream); } }
From source file:net.sf.taverna.t2.renderers.RendererUtils.java
public static long getSizeInBytes(Path path) throws IOException { if (isValue(path)) return Files.size(path); if (!isReference(path)) throw new IllegalArgumentException("Path is not a value or reference"); URL url = getReference(path).toURL(); switch (url.getProtocol().toLowerCase()) { case "http": case "https": HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("HEAD"); conn.connect();/*from w w w .j ava 2s . c o m*/ String contentLength = conn.getHeaderField("Content-Length"); conn.disconnect(); if (contentLength != null && !contentLength.isEmpty()) return Long.parseLong(contentLength); return -1; case "file": return FileUtils.toFile(url).length(); default: return -1; } }
From source file:com.moss.appkeep.tools.cache.SimpleAppkeepComponentCache.java
private static String dirNameForUrl(String url) { try {// w ww .j ava 2 s. co m URL u = new URL(url); return u.getProtocol() + "_" + u.getHost() + "_" + u.getPort() + "_" + u.getPath().replaceAll(Pattern.quote("/"), "_"); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:at.beris.virtualfile.util.UrlUtils.java
public static Protocol getProtocol(URL url) { return Protocol.valueOf(url.getProtocol().toUpperCase()); }
From source file:com.athomas.androidkickstartr.util.ResourcesUtils.java
public static void copyResourcesTo(File resourcesDir, String filepathMarker) throws IOException { if (resourcesDir == null) { throw new IllegalArgumentException("The resources dir must not be null"); }/* w w w . j a v a 2 s. com*/ ClassLoader classLoader = ResourcesUtils.class.getClassLoader(); URL url = classLoader.getResource(filepathMarker); String protocol = url.getProtocol(); if (protocol.equals("file")) { File src = new File("src/main/resources"); FileUtils.copyDirectory(src, resourcesDir); } else if (protocol.equals("jar")) { copyResourcesToFromJar(resourcesDir, url); } }