Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

In this page you can find the example usage for java.net URL toURI.

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:org.jboss.additional.testsuite.jdkall.present.domain.management.cli.DomainDeploymentOverlayTestCase.java

@BeforeClass
public static void before() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");

    WebArchive war;/*from   w w  w  .  java  2 s  .co m*/

    // deployment1
    war = ShrinkWrap.create(WebArchive.class, "deployment0.war");
    war.addClass(SimpleServlet.class);
    war.addAsWebInfResource("cli/deployment-overlay/web.xml", "web.xml");
    war1 = new File(tempDir + File.separator + war.getName());
    new ZipExporterImpl(war).exportTo(war1, true);

    war = ShrinkWrap.create(WebArchive.class, "deployment1.war");
    war.addClass(SimpleServlet.class);
    war.addAsWebInfResource("cli/deployment-overlay/web.xml", "web.xml");
    war2 = new File(tempDir + File.separator + war.getName());
    new ZipExporterImpl(war).exportTo(war2, true);

    war = ShrinkWrap.create(WebArchive.class, "another.war");
    war.addClass(SimpleServlet.class);
    war.addAsWebInfResource("cli/deployment-overlay/web.xml", "web.xml");
    war3 = new File(tempDir + File.separator + war.getName());
    new ZipExporterImpl(war).exportTo(war3, true);

    final URL overrideXmlUrl = DomainDeploymentOverlayTestCase.class.getClassLoader()
            .getResource("cli/deployment-overlay/override.xml");
    if (overrideXmlUrl == null) {
        Assert.fail("Failed to locate cli/deployment-overlay/override.xml");
    }
    overrideXml = new File(overrideXmlUrl.toURI());
    if (!overrideXml.exists()) {
        Assert.fail("Failed to locate cli/deployment-overlay/override.xml");
    }

    final URL webXmlUrl = DomainDeploymentOverlayTestCase.class.getClassLoader()
            .getResource("cli/deployment-overlay/web.xml");
    if (webXmlUrl == null) {
        Assert.fail("Failed to locate cli/deployment-overlay/web.xml");
    }
    webXml = new File(webXmlUrl.toURI());
    if (!webXml.exists()) {
        Assert.fail("Failed to locate cli/deployment-overlay/web.xml");
    }

    // Launch the domain
    testSupport = CLITestSuite.createSupport(DomainDeploymentOverlayTestCase.class.getSimpleName());
}

From source file:com.tesora.dve.common.PEFileUtils.java

private static String getCanonicalPathFromURL(final URL url) throws PEException {
    File resourceFile;/*w w  w .jav  a 2s .c o  m*/
    try {
        final String os = System.getProperty("os.name");
        if (StringUtils.containsIgnoreCase(os, "win")) {
            return url.getFile();
        }

        resourceFile = new File(url.toURI());
    } catch (final URISyntaxException e) {
        resourceFile = new File(url.getPath());
    }

    try {
        return resourceFile.getCanonicalPath();
    } catch (final IOException e) {
        throw new PEException("Could not canonicalize the path '" + resourceFile.getAbsolutePath() + "'", e);
    }
}

From source file:net.paoding.analysis.knife.PaodingMaker.java

private static String getUrlPath(URL url) {
    if (url == null)
        return null;
    String urlPath = null;/*from   w ww. j a v a  2 s. com*/
    try {
        urlPath = url.toURI().getPath();
    } catch (URISyntaxException e) {
    }
    if (urlPath == null) {
        urlPath = url.getFile();
    }
    return urlPath;
}

From source file:org.eclipse.wst.json.core.internal.download.HttpClientProvider.java

private static long getLastModified(URL url) {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpResponse response = null;
    try {//from   w w  w  . j a va 2 s . c o  m
        HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
        Builder builder = RequestConfig.custom();
        HttpHost proxy = getProxy(target);
        if (proxy != null) {
            builder = builder.setProxy(proxy);
        }
        RequestConfig config = builder.build();
        HttpHead request = new HttpHead(url.toURI());
        request.setConfig(config);
        response = httpclient.execute(target, request);
        Header[] s = response.getHeaders("last-modified");
        if (s != null && s.length > 0) {
            String lastModified = s[0].getValue();
            return new Date(lastModified).getTime();
        }
    } catch (Exception e) {
        logWarning(e);
        return -1;
    } finally {
        if (response != null) {
            try {
                response.close();
            } catch (IOException e) {
            }
        }
        try {
            httpclient.close();
        } catch (IOException e) {
        }
    }
    return -1;
}

From source file:org.apache.hadoop.gateway.GatewayAppFuncTest.java

public static void setupLdap() throws Exception {
    URL usersUrl = TestUtils.getResourceUrl(DAT, "users.ldif");
    ldapTransport = new TcpTransport(0);
    ldap = new SimpleLdapDirectoryServer("dc=hadoop,dc=apache,dc=org", new File(usersUrl.toURI()),
            ldapTransport);/*from ww w .  ja v  a 2  s .  c o m*/
    ldap.start();
    ldapPort = ldapTransport.getAcceptor().getLocalAddress().getPort();
    LOG.info("LDAP port = " + ldapPort);
}

From source file:org.eclipse.cft.server.core.internal.client.CloudFoundryClientFactory.java

public static HttpProxyConfiguration getProxy(URL url) {
    if (url == null) {
        return null;
    }/*from  w w  w .j  a v  a 2  s.co m*/
    // In certain cases, the activator would have stopped and the plugin may
    // no longer be available. Usually onl happens on shutdown.
    CloudFoundryPlugin plugin = CloudFoundryPlugin.getDefault();
    if (plugin != null) {
        IProxyService proxyService = plugin.getProxyService();
        if (proxyService != null) {
            try {
                IProxyData[] selectedProxies = proxyService.select(url.toURI());

                // No proxy configured or not found
                if (selectedProxies == null || selectedProxies.length == 0) {
                    return null;
                }

                IProxyData data = selectedProxies[0];
                int proxyPort = data.getPort();
                String proxyHost = data.getHost();
                String user = data.getUserId();
                String password = data.getPassword();
                return proxyHost != null
                        ? new HttpProxyConfiguration(proxyHost, proxyPort, data.isRequiresAuthentication(),
                                user, password)
                        : null;
            } catch (URISyntaxException e) {
                // invalid url (protocol, ...) => proxy will be null
            }
        }
    }
    return null;
}

From source file:org.apache.hadoop.gateway.GatewayAdminTopologyFuncTest.java

public static void setupLdap() throws Exception {
    URL usersUrl = getResourceUrl("users.ldif");
    ldapTransport = new TcpTransport(0);
    ldap = new SimpleLdapDirectoryServer("dc=hadoop,dc=apache,dc=org", new File(usersUrl.toURI()),
            ldapTransport);// w  ww . java 2s .  c  o  m
    ldap.start();
    LOG.info("LDAP port = " + ldapTransport.getAcceptor().getLocalAddress().getPort());
}

From source file:com.dtolabs.rundeck.ExpandRunServer.java

/**
 * Return file for the enclosing jar/*from www  .j a v a 2 s  .  c o  m*/
 *
 * @return
 *
 * @throws URISyntaxException
 */
private static File thisJarFile() {
    final ProtectionDomain protectionDomain = ExpandRunServer.class.getProtectionDomain();
    final URL location = protectionDomain.getCodeSource().getLocation();
    try {
        return new File(location.toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.alpharogroup.lang.ClassUtils.java

/**
 * Gives the resource as a file Object./*w w  w .  ja v  a  2 s  .  c o  m*/
 *
 * @param name
 *            The name from the file.
 * @return The file or null if the file does not exists.
 * @throws URISyntaxException
 *             occurs by creation of the file with an uri.
 */
public static File getResourceAsFile(final String name) throws URISyntaxException {
    File file = null;
    URL url = getResource(name);
    if (null == url) {
        url = ClassUtils.getClassLoader().getResource(name);
        if (null != url) {
            file = new File(url.toURI());
        }
    } else {
        file = new File(url.toURI());
    }
    return file;
}

From source file:com.depas.utils.FileUtils.java

/**
 * Gets the root directory that we will initialize the GEN3 license framework.
 * @param c the c//  w ww.  j a  v a2 s.c  om
 * @return the license root path
 */
public static String getLicensingRootPath(Class<?> c) {
    try {
        // get url to iwc directory on classpath
        URL url = ClassLoader.getSystemResource("iwc");
        if (url != null) {
            File iwcDir = new File(url.toURI());
            // go up one to ignite_config
            // go up one more then to root
            File baseDir = iwcDir.getParentFile().getParentFile();

            String path = baseDir.getPath();
            if (path.endsWith("\\") == false && path.endsWith("/") == false) {
                path += "/";
            }
            // licensing, should be at same level as ignite_config
            path += "licensing/";
            return URLDecoder.decode(path, "UTF-8");
        } else {
            return null;
        }
    } catch (Exception ex) {
        logger.warn("Error obtaining file path to license directory: " + ex);
        return null;
    }
}