List of usage examples for java.net URL toString
public String toString()
From source file:kontrol.HttpUtil.java
public static InputStream getUrlAsStream(URL url, int timeout, Locale locale) throws IOException { return getUrlAsStream(URI.create(url.toString()), timeout, locale); }
From source file:kontrol.HttpUtil.java
public static String getUrlAsString(URL url, int timeout, Locale locale) throws IOException { return getUrlAsString(URI.create(url.toString()), timeout, locale); }
From source file:ca.sqlpower.enterprise.ServerInfoProvider.java
private static String generateServerKey(URL url, String username, String password) { return String.valueOf(url.toString().concat(username).concat(password).hashCode()); }
From source file:com.mockey.runner.JettyRunner.java
private static void initializeMockey(URL initUrl) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(initUrl.toString()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("Initialized mockey with request: " + initUrl.toString()); System.out.println("Response: " + entity.getContent()); }
From source file:de.mpg.escidoc.services.common.util.ProxyHelper.java
/** * Returns <code>java.net.URLConnection</code> with the Proxy settings * creation// w w w . j a v a2 s . co m * * @param url url * @throws IOException * * @throws Exception * @return URLConnection */ public static URLConnection openConnection(final URL url) throws IOException { return url.openConnection(getProxy(url.toString())); }
From source file:marytts.tools.install.LicenseRegistry.java
private static void saveIndex() { assert remote2local != null; File downloadDir = new File(System.getProperty("mary.downloadDir", ".")); File licenseIndexFile = new File(downloadDir, "license-index.txt"); try (PrintWriter pw = new PrintWriter( new OutputStreamWriter(new FileOutputStream(licenseIndexFile), "UTF-8"))) { for (URL remote : remote2local.keySet()) { pw.println(remote2local.get(remote) + "|" + remote.toString()); }//from w w w.ja v a2 s . c om } catch (IOException e) { System.err.println("Problem updating the index file " + licenseIndexFile.getAbsolutePath()); e.printStackTrace(); } }
From source file:de.renew.workflow.connector.internal.cases.ScenarioCompatibilityHelper.java
public static boolean ensureBackwardsCompatibility(final ScenarioHandlingProjectNature nature) { // FIXME: this is dirty fix only for this release 2.3 // should be implemented in other way, we just do not have any time now try {/*from w ww .ja va 2 s. c o m*/ if (nature == null || !nature.getProject().hasNature("org.kalypso.kalypso1d2d.pjt.Kalypso1D2DProjectNature")) //$NON-NLS-1$ return true; // FIXME: the whole code here does not belong to this place -> this is a hidden dependency to 1d2d: bad! // TODO: instead implement an extension point mechanism final ProjectTemplate[] lTemplate = EclipsePlatformContributionsExtensions .getProjectTemplates("org.kalypso.kalypso1d2d.pjt.projectTemplate"); //$NON-NLS-1$ try { // FIXME: this very probably does not work correctly or any more at all! /* Unpack project from template */ final File destinationDir = nature.getProject().getLocation().toFile(); final URL data = lTemplate[0].getData(); final String location = data.toString(); final String extension = FilenameUtils.getExtension(location); if ("zip".equalsIgnoreCase(extension)) //$NON-NLS-1$ { // TODO: this completely overwrite the old project content, is this intended? ZipUtilities.unzip(data.openStream(), destinationDir, false); } else { final URL fileURL = FileLocator.toFileURL(data); final File dataDir = FileUtils.toFile(fileURL); if (dataDir == null) { return false; } // FIXME: this only fixes the basic scenario, is this intended? final IOFileFilter lFileFilter = new WildcardFileFilter(new String[] { "wind.gml" }); //$NON-NLS-1$ final IOFileFilter lDirFilter = TrueFileFilter.INSTANCE; final Collection<?> windFiles = FileUtils.listFiles(destinationDir, lFileFilter, lDirFilter); if (dataDir.isDirectory() && (windFiles == null || windFiles.size() == 0)) { final WildcardFileFilter lCopyFilter = new WildcardFileFilter( new String[] { "*asis", "models", "wind.gml" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ FileUtils.copyDirectory(dataDir, destinationDir, lCopyFilter); } else { return true; } } } catch (final Throwable t) { t.printStackTrace(); return false; } nature.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (final CoreException e) { // FIXME: this is no error handling; the users are not informed and will stumble over following errors caued by // this problem WorkflowConnectorPlugin.getDefault().getLog().log(e.getStatus()); e.printStackTrace(); return false; } return true; }
From source file:com.linkedin.pinot.common.utils.SchemaUtils.java
/** * Given host, port and schema, send a http POST request to upload the {@link Schema}. * * @return <code>true</code> on success. * <P><code>false</code> on failure. *///from w w w . j a v a 2 s . co m public static boolean postSchema(@Nonnull String host, int port, @Nonnull Schema schema) { Preconditions.checkNotNull(host); Preconditions.checkNotNull(schema); try { URL url = new URL("http", host, port, "/schemas"); PostMethod httpPost = new PostMethod(url.toString()); try { Part[] parts = { new StringPart(schema.getSchemaName(), schema.toString()) }; MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, new HttpMethodParams()); httpPost.setRequestEntity(requestEntity); int responseCode = HTTP_CLIENT.executeMethod(httpPost); if (responseCode >= 400) { String response = httpPost.getResponseBodyAsString(); LOGGER.warn("Got error response code: {}, response: {}", responseCode, response); return false; } return true; } finally { httpPost.releaseConnection(); } } catch (Exception e) { LOGGER.error("Caught exception while posting the schema: {} to host: {}, port: {}", schema.getSchemaName(), host, port, e); return false; } }
From source file:com.diversityarrays.util.ClassPathExtender.java
public static void addDirectoryJarsToClassPath(Log logger, Consumer<File> jarChecker, File... dirs) { if (dirs == null || dirs.length <= 0) { if (logger != null) { logger.info("No directories provided for class path"); }//from www.j a v a 2 s . co m return; } ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl instanceof java.net.URLClassLoader) { try { Method m = java.net.URLClassLoader.class.getDeclaredMethod("addURL", URL.class); m.setAccessible(true); Set<URL> currentUrls = new HashSet<URL>(Arrays.asList(((URLClassLoader) ccl).getURLs())); if (VERBOSE) { info(logger, "=== Current URLS in ClassLoader: " + currentUrls.size()); for (URL u : currentUrls) { info(logger, "\t" + u.toString()); } } for (File dir : dirs) { if (dir.isDirectory()) { for (File f : dir.listFiles(JAR_OR_PROPERTIES)) { try { URL u = f.toURI().toURL(); if (!currentUrls.contains(u)) { m.invoke(ccl, u); if (VERBOSE) { info(logger, "[Added " + u + "] to CLASSPATH"); } if (jarChecker != null) { jarChecker.accept(f); } } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | MalformedURLException e) { warn(logger, "%Unable to add " + f.getPath() + " to CLASSPATH (" + e.getMessage() + ")"); } } } } } catch (NoSuchMethodException e) { warn(logger, "%No method: " + java.net.URLClassLoader.class.getName() + ".addURL(URL)"); } } else { warn(logger, "%currentThread.contextClassLoader is not an instance of " + java.net.URLClassLoader.class.getName()); } }
From source file:org.pentaho.marketplace.util.web.HttpUtil.java
public static InputStream getURLInputStream(final URL url) { return getURLInputStream(url.toString()); }