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:com.netflix.nicobar.core.archive.JarScriptArchiveTest.java

@Test
public void testDefaultModuleId() throws Exception {
    URL rootPathUrl = getClass().getClassLoader().getResource(TEST_DEFAULT_MODULE_SPEC_JAR.getResourcePath());
    Path rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath();
    JarScriptArchive scriptArchive = new JarScriptArchive.Builder(rootPath).build();
    assertEquals(scriptArchive.getModuleSpec().getModuleId(), TEST_DEFAULT_MODULE_SPEC_JAR.getModuleId());

    rootPathUrl = getClass().getClassLoader().getResource(TEST_DEFAULT_MODULE_SPEC_JAR2.getResourcePath());
    rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath();
    scriptArchive = new JarScriptArchive.Builder(rootPath).build();
    assertEquals(scriptArchive.getModuleSpec().getModuleId(), TEST_DEFAULT_MODULE_SPEC_JAR2.getModuleId());
}

From source file:gov.nih.nci.cacis.cdw.BaseVirtuosoIntegrationTest.java

/**
 * Gets a valid Message. Default implementation reads a valid SOAPMessage that has been serialized to a file.
 *
 * @return string representation of a valid message
 * @throws IOException on I/O error//from   w ww . j a  va2 s. c o  m
 * @throws URISyntaxException on URI Syntax error
 */
protected String getValidMessage() throws IOException, URISyntaxException {
    final URL url = getClass().getClassLoader().getResource(SOAP_MSG_FILENAME);
    return FileUtils.readFileToString(new File(url.toURI()));
}

From source file:it.geosolutions.geostore.core.security.password.EncodingTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    String[] paths = { "classpath*:encoders-context-test.xml" };
    context = new ClassPathXmlApplicationContext(paths);
    URL url = this.getClass().getResource("/geostore.jceks");
    File f = new File(url.toURI());

    //plain text master password
    URL passFile = this.getClass().getResource("/passwd-test");
    URLMasterPasswordProvider pp = new URLMasterPasswordProvider();
    pp.setEncrypting(false);/*from www. j  ava2  s .com*/
    pp.setURL(passFile);
    passwd = pp.doGetMasterPassword();
    if (f.exists()) {
        KeyStoreProviderImpl ksp = (KeyStoreProviderImpl) context.getBean("keyStoreProvider");
        ksp.setKeyStoreFilePath(f.getAbsolutePath());
        ksp.setMasterPassword(passwd);

    }

}

From source file:neembuu.uploader.captcha.ImagePanel.java

public final void update(URL imageFileUrl, HttpContext httpContext) {
    try {//from   w w  w.  j a va  2  s  .  co  m
        HttpClient httpClient = NUHttpClient.getHttpClient();
        HttpGet httpGet = new HttpGet(imageFileUrl.toURI());
        HttpResponse httpresponse = httpClient.execute(httpGet, httpContext);
        byte[] imageInByte = EntityUtils.toByteArray(httpresponse.getEntity());
        InputStream in = new ByteArrayInputStream(imageInByte);
        image = ImageIO.read(in);
        //image = ImageIO.read(imageFileUrl);
    } catch (Exception ex) {
        NULogger.getLogger().log(Level.INFO, "ImagePanel exception: {0}", ex.getMessage());
    }
}

From source file:com.spotify.docker.client.CompressedDirectoryTest.java

@Test
public void testFileWithIgnore() throws Exception {
    // note: Paths.get(someURL.toUri()) is the platform-neutral way to convert a URL to a Path
    final URL dockerDirectory = Resources.getResource("dockerDirectoryWithIgnore");
    try (CompressedDirectory dir = CompressedDirectory.create(Paths.get(dockerDirectory.toURI()));
            BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
            GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
            TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {

        final List<String> names = new ArrayList<>();
        TarArchiveEntry entry;//  www.j a va 2 s  .c  o  m
        while ((entry = tarIn.getNextTarEntry()) != null) {
            final String name = entry.getName();
            names.add(name);
        }
        assertThat(names, containsInAnyOrder("Dockerfile", "bin/date.sh", "subdir2/keep-me", ".dockerignore"));
    }
}

From source file:com.googlecode.fascinator.common.BasicHttpClient.java

/**
 * Gets an HTTP client. If authentication is required, the authenticate()
 * method must be called prior to this method.
 * /*from   w ww.  j  a v  a  2s .  co  m*/
 * @param auth set true to use authentication, false to skip authentication
 * @return an HTTP client
 */
public HttpClient getHttpClient(boolean auth) {
    HttpClient client = new HttpClient();
    try {
        URL url = new URL(baseUrl);
        Proxy proxy = ProxySelector.getDefault().select(url.toURI()).get(0);
        if (!proxy.type().equals(Proxy.Type.DIRECT)) {
            InetSocketAddress address = (InetSocketAddress) proxy.address();
            String proxyHost = address.getHostName();
            int proxyPort = address.getPort();
            client.getHostConfiguration().setProxy(proxyHost, proxyPort);
            log.trace("Using proxy {}:{}", proxyHost, proxyPort);
        }
    } catch (Exception e) {
        log.warn("Failed to get proxy settings: " + e.getMessage());
    }
    if (auth && credentials != null) {
        client.getParams().setAuthenticationPreemptive(true);
        client.getState().setCredentials(AuthScope.ANY, credentials);
        log.trace("Credentials: username={}", credentials.getUserName());
    }
    return client;
}

From source file:azkaban.database.AzkabanDatabaseUpdaterTest.java

@Test
public void testH2AutoCreate() throws Exception {
    URL resourceUrl = Resources.getResource("conf/dbtesth2");
    assertNotNull(resourceUrl);/* w  w  w  .j ava2s  . c  o  m*/
    File resource = new File(resourceUrl.toURI());
    String confDir = resource.getParent();

    System.out.println("1.***Now testing check");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });

    System.out.println("2.***Now testing update");
    AzkabanDatabaseUpdater.main(new String[] { "-u", "-c", confDir });

    System.out.println("3.***Now testing check again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });

    System.out.println("4.***Now testing update again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir, "-u" });

    System.out.println("5.***Now testing check again");
    AzkabanDatabaseUpdater.main(new String[] { "-c", confDir });
}

From source file:com.netflix.nicobar.core.archive.PathScriptArchiveTest.java

@Test
public void testLoadWithModuleSpec() throws Exception {
    URL rootPathUrl = getClass().getClassLoader().getResource(TEST_MODULE_SPEC_PATH.getResourcePath());
    Path rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath();

    // if the module spec isn't provided, it should be discovered in the path
    PathScriptArchive scriptArchive = new PathScriptArchive.Builder(rootPath).build();
    ScriptModuleSpec moduleSpec = scriptArchive.getModuleSpec();
    assertEquals(moduleSpec.getModuleId(), TEST_MODULE_SPEC_PATH.getModuleId());
    assertEquals(moduleSpec.getModuleDependencies(), Collections.emptySet());
    Map<String, Object> expectedMetadata = new HashMap<String, Object>();
    Map<String, String> expectedMetadata1 = new HashMap<String, String>();

    expectedMetadata1.put("nestedKey1", "metadataValue1");
    expectedMetadata1.put("nestedKey2", "metadataValue2");

    expectedMetadata.put("metadataName1", expectedMetadata1);
    expectedMetadata.put("metadataName2", 2.0);
    expectedMetadata.put("metadataName3", Arrays.asList(1.0, 2.0, 3.0));
    Map<String, Object> somedata = moduleSpec.getMetadata();
    assertEquals(somedata, expectedMetadata);
}

From source file:org.sakuli.services.common.CacheHandlingResultServiceImplTest.java

protected Path getResource(String fileName, boolean exists) throws URISyntaxException {
    URL filePath = this.getClass().getResource(fileName);
    if (exists) {
        assertNotNull(filePath);//  w w  w . j av  a  2  s . c o m
        return Paths.get(filePath.toURI());
    }
    assertNull(filePath);
    return null;
}

From source file:libraryjava.parseJSON.java

/**
 * method Bitmap deprecated//from   w  ww. j  a v  a 2s.  c  o m
 * @param urll
 * @return
 */
public Bitmap doInBackgroundDeprecated(String urll) {
    StrictMode();

    try {
        URL url = new URL(urll);

        HttpGet httpRequest = new HttpGet(url.toURI());
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(httpRequest);

        HttpEntity entity = response.getEntity();
        BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
        InputStream input = bufferedEntity.getContent();

        return BitmapFactory.decodeStream(input);

    } catch (Exception ex) {
        return null;
    }
}