List of usage examples for java.net URL toString
public String toString()
From source file:com.facultyshowcase.app.ui.UIUtil.java
public static void writeProperty(EntityUtilWriter writer, String htmlClass, String label, URL link) { writeContainerBeginning(writer, htmlClass); writeLabel(writer, htmlClass, label); if (link != null) { writer.append("<a ").appendEscapedAttribute("href", link.toString()).append(">"); writer.append("<span "); writer.appendEscapedAttribute(CLASS, CmsHTMLClassNames.convertClassName(PROP + " " + htmlClass)); writer.append(">"); writer.appendEscapedData(StringUtils.substringAfter(link.toString(), "://")); writer.append("</span>"); writer.append("</a>"); } else {/*from w w w . ja va2 s .c o m*/ writer.append("<span "); writer.appendEscapedAttribute(CLASS, CmsHTMLClassNames.convertClassName(PROP + " " + htmlClass)); writer.append(">"); writer.append("</span>"); } writeContainerEnd(writer); }
From source file:com.nesscomputing.httpclient.testsupport.LocalHttpService.java
private static Connector getSSLHttpConnector() { final URL keystoreUrl = Resources.getResource(LocalHttpService.class, "/ssl-server-keystore.jks"); final SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath(keystoreUrl.toString()); contextFactory.setKeyStorePassword("changeit"); contextFactory.setKeyManagerPassword("changeit"); final SslSelectChannelConnector scc = new SslSelectChannelConnector(contextFactory); scc.setPort(0);/*from w w w . j a v a 2s. c o m*/ scc.setHost("localhost"); return scc; }
From source file:com.nesscomputing.config.util.LocalHttpService.java
private static Connector getSSLHttpConnector() { final URL keystoreUrl = Resources.getResource(LocalHttpService.class, "/test-server-keystore.jks"); final SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath(keystoreUrl.toString()); contextFactory.setKeyStorePassword("changeit"); contextFactory.setKeyManagerPassword("changeit"); final SslSelectChannelConnector scc = new SslSelectChannelConnector(contextFactory); scc.setPort(0);/*from w w w . j a v a 2 s . com*/ scc.setHost("localhost"); return scc; }
From source file:com.norconex.commons.lang.url.URLStreamer.java
/** * Streams URL content.// w w w. j av a 2 s . com * @param url the URL to stream * @param creds credentials for a protected URL * @param proxy proxy to use to stream the URL * @param proxyCreds credentials to access the proxy * @return a URL content InputStream */ public static InputStream stream(URL url, Credentials creds, HttpHost proxy, Credentials proxyCreds) { return stream(url.toString(), creds, proxy, proxyCreds); }
From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java
public static String getJsonResponse(String s) { HttpURLConnection connection = null; InputStream input = null;// ww w. j a v a 2s. co m BufferedReader reader = null; String JsonResponse = null; try { URL url = new URL(s); Log.d("TAG", url.toString()); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); input = connection.getInputStream(); StringBuilder builder = new StringBuilder(); if (input != null) { reader = new BufferedReader(new InputStreamReader(input)); String line; while ((line = reader.readLine()) != null) { builder.append(line).append("\n"); } JsonResponse = builder.toString(); } } catch (IOException e) { e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } if (input != null) { try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } return JsonResponse; }
From source file:AnimatedMetadataGraph.java
public static JSONArray getChildren(URL sfsUrl, String path) { if (sfsUrl != null) { try {/* ww w . jav a 2 s. c o m*/ URL sfsGetRsrcsUrl = new URL(sfsUrl.toString() + path); URLConnection smapConn = sfsGetRsrcsUrl.openConnection(); smapConn.setConnectTimeout(5000); smapConn.connect(); //GET reply BufferedReader reader = new BufferedReader(new InputStreamReader(smapConn.getInputStream())); StringBuffer lineBuffer = new StringBuffer(); String line = null; while ((line = reader.readLine()) != null) lineBuffer.append(line); line = lineBuffer.toString(); reader.close(); JSONObject resp = (JSONObject) JSONSerializer.toJSON(line); return resp.optJSONArray("children"); } catch (Exception e) { logger.log(Level.WARNING, "", e); return null; } } return null; }
From source file:$.FileUtils.java
public static void urlToPath(URL url, File fOut) throws IOException { URLConnection uc = url.openConnection(); logger.info("ContentType: " + uc.getContentType()); InputStream in = uc.getInputStream(); org.apache.commons.io.FileUtils.copyInputStreamToFile(in, fOut); logger.info("File of length " + fOut.length() + " created from URL " + url.toString()); in.close();/*from ww w .ja v a 2 s. c o m*/ }
From source file:Which4J.java
/** * Iterate over the system classpath defined by "java.class.path" searching * for all occurrances of the given class name. * /*from w ww. j a v a 2 s.c o m*/ * @param classname the fully qualified class name to search for */ private static void findIt(String classname) { try { // get the system classpath String classpath = System.getProperty("java.class.path", ""); if (classpath.equals("")) { System.err.println("error: classpath is not set"); } if (debug) { System.out.println("classname: " + classname); System.out.println("system classpath = " + classpath); } if (isPrimitiveOrVoid(classname)) { System.out.println("'" + classname + "' primitive"); return; } StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); while (st.hasMoreTokens()) { String token = st.nextToken(); File classpathElement = new File(token); if (debug) System.out.println(classpathElement.isDirectory() ? "dir: " + token : "jar: " + token); URL[] url = { classpathElement.toURL() }; URLClassLoader cl = URLClassLoader.newInstance(url, null); String classnameAsResource = classname.replace('.', '/') + ".class"; URL it = cl.findResource(classnameAsResource); if (it != null) { System.out.println("found in: " + token); System.out.println(" url: " + it.toString()); System.out.println(""); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.norconex.commons.lang.url.URLStreamer.java
/** * Streams URL content to a String.// w w w . j av a 2 s. co m * @param url the URL to stream * @param creds credentials for a protected URL * @param proxy proxy to use to stream the URL * @param proxyCreds credentials to access the proxy * @return a URL content as a String */ public static String streamToString(URL url, Credentials creds, HttpHost proxy, Credentials proxyCreds) { return streamToString(url.toString(), creds, proxy, proxyCreds); }
From source file:com.moviejukebox.plugin.trailer.AppleTrailersPlugin.java
private static String getAbsUrl(String baseUrl, String relativeUrl) { try {//w w w . jav a 2s. c om URL baseURL = new URL(baseUrl); URL absURL = new URL(baseURL, relativeUrl); return absURL.toString(); } catch (MalformedURLException ex) { return Movie.UNKNOWN; } }