List of usage examples for java.net URL toString
public String toString()
From source file:Main.java
public static String getNoQueryUrl(String source) { String dest = null;//ww w.j av a2s.c o m try { URL sUrl = new URL(source); URL dUrl = new URL(sUrl.getProtocol(), sUrl.getHost(), sUrl.getPort(), sUrl.getPath()); dest = dUrl.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } return dest; }
From source file:com.clustercontrol.plugin.ClassUtils.java
/** * ??URLCLASSPATH??<br/>/*from w w w . j a va2s .c o m*/ * @param ?URL * @throws IOException */ public static void addURL(URL u) throws IOException { URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); for (URL url : sysLoader.getURLs()) { if (url.toString().equals(u.toString())) { log.info("URL " + u + " is already in CLASSPATH"); return; } } Class<URLClassLoader> sysClass = URLClassLoader.class; try { Method method = sysClass.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(sysLoader, new Object[] { u }); } catch (Throwable t) { log.warn(t.getMessage(), t); throw new IOException("could not add URL " + u + " to CLASSPATH"); } }
From source file:com.codebutler.rsp.Util.java
public static String getURL(URL url, String password) throws Exception { Log.i("Util.getURL", url.toString()); DefaultHttpClient client = new DefaultHttpClient(); if (password != null && password.length() > 0) { UsernamePasswordCredentials creds; creds = new UsernamePasswordCredentials("user", password); client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); }//w w w .j av a 2 s .c o m HttpGet method = new HttpGet(url.toURI()); BasicResponseHandler responseHandler = new BasicResponseHandler(); return client.execute(method, responseHandler); }
From source file:com.surfs.storage.common.util.HttpUtils.java
public static String invokeHttpForGet(String path, String... agrs) throws IOException { URL url = new URL(path); LogFactory.info("rest url:" + url.toString()); HttpURLConnection con = null; try {// w ww .j av a 2 s .co m con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setConnectTimeout(10000); con.setReadTimeout(1000 * 60 * 30); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); for (String string : agrs) { con.setRequestProperty("Content-type", "application/json"); con.setRequestMethod("POST"); OutputStream out = con.getOutputStream(); out.write(string.getBytes("UTF-8")); } if (con.getResponseCode() != 200) throw new ConnectException(con.getResponseMessage()); InputStream is = con.getInputStream(); return readResponse(is); } catch (IOException e) { throw e; } finally { if (con != null) { con.disconnect(); } } }
From source file:eu.scape_project.pit.util.FileUtils.java
/** * @param inputUrl/*from ww w. j a v a 2 s .c o m*/ * @return the file name derived from the URL */ public static String getFileNameFromUrl(URL inputUrl) { String urlStr = inputUrl.toString(); String fileName = urlStr.substring(urlStr.lastIndexOf("/") + 1); return fileName; }
From source file:$.FileUtils.java
public static String getFileNameFromUrl(URL inputUrl) { String urlStr = inputUrl.toString(); String fileName = urlStr.substring(urlStr.lastIndexOf("/") + 1); return fileName; }//from ww w . ja v a 2s .c o m
From source file:com.arrow.acs.ManifestUtils.java
public static Manifest readManifest(Class<?> clazz) { String method = "readManifest"; String jarFile = null;/*from w w w .jav a2 s . co m*/ String path = clazz.getProtectionDomain().getCodeSource().getLocation().toString(); for (String token : path.split("/")) { token = token.replace("!", "").toLowerCase().trim(); if (token.endsWith(".jar")) { jarFile = token; break; } } LOGGER.logInfo(method, "className: %s, path: %s, jarFile: %s", clazz.getName(), path, jarFile); InputStream is = null; try { if (!StringUtils.isEmpty(jarFile)) { Enumeration<URL> enumeration = Thread.currentThread().getContextClassLoader() .getResources(JarFile.MANIFEST_NAME); while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); for (String token : url.toString().split("/")) { token = token.replace("!", "").toLowerCase(); if (token.equals(jarFile)) { LOGGER.logInfo(method, "loading manifest from: %s", url.toString()); return new Manifest(is = url.openStream()); } } } } else { URL url = new URL(path + "/META-INF/MANIFEST.MF"); LOGGER.logInfo(method, "loading manifest from: %s", url.toString()); return new Manifest(is = url.openStream()); } } catch (IOException e) { } finally { IOUtils.closeQuietly(is); } LOGGER.logError(method, "manifest file not found for: %s", clazz.getName()); return null; }
From source file:at.beris.virtualfile.util.UrlUtils.java
public static URL normalizeUrl(URL url) throws IOException { URI uri = URI.create(url.toString()); return uri.normalize().toURL(); }
From source file:no.norrs.projects.andronary.service.utils.HttpUtil.java
public static HttpResponse DEL(final URL uri) throws IOException { return DEL(uri.toString()); }
From source file:Main.java
/** * Write an {@link URL} value into XML output. * * @param value//from ww w. j a v a2 s .co m * value to write * * @return * XML string * * @throws IllegalArgumentException * if a validation error occured */ public static String printUrl(URL value) { if (value == null) { throw new IllegalArgumentException("The provided URL NULL is invalid!"); } return value.toString(); }