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.google.appengine.tck.endpoints.support.EndPointClient.java

public String doDelete(URL url) throws Exception {
    return doRequest(new HttpDelete(url.toURI()));
}

From source file:com.guardtime.ksi.service.client.http.apache.ApacheHttpClient.java

private ApacheHttpPostRequestFuture post(InputStream request, URL url) throws KSIClientException {
    try {//from   w  ww  . j a v  a2s.co m
        HttpPost httpRequest = new HttpPost(url.toURI());
        httpRequest.setHeader(AbstractHttpClient.HEADER_NAME_CONTENT_TYPE,
                AbstractHttpClient.HEADER_APPLICATION_KSI_REQUEST);
        ByteArrayEntity entity = new ByteArrayEntity(Util.toByteArray(request));
        entity.setChunked(false);
        httpRequest.setEntity(entity);
        Future<HttpResponse> future = this.apacheClient.execute(httpRequest, null);
        return new ApacheHttpPostRequestFuture(future);
    } catch (URISyntaxException e) {
        throw new KSIClientException("Invalid URI " + settings.getSigningUrl(), e);
    } catch (IOException e) {
        throw new KSIClientException("Reading data from stream failed", e);
    }
}

From source file:de.lmu.ifi.dbs.jfeaturelib.utils.PackageScanner.java

List<String> getNames(Package inPackage)
        throws UnsupportedEncodingException, URISyntaxException, ZipException, IOException {
    List<String> binaryNames = new ArrayList<>();

    String packagePath = inPackage.getName();
    packagePath = packagePath.replace('.', '/');

    // During tests, this points to the classes/ directory, later, this points to the jar
    CodeSource src = PackageScanner.class.getProtectionDomain().getCodeSource();
    URL location = src.getLocation();
    // test case/*  w  w  w.  j  a  v a2  s. c  o  m*/
    File dirOrJar = new File(location.toURI());
    if (dirOrJar.isDirectory()) {
        // +1 to include the slash after the directory name
        int basePathLength = dirOrJar.toString().length() + 1;
        File packageDir = new File(dirOrJar, packagePath);

        // list all .class files in this package directory
        for (File file : packageDir.listFiles((FilenameFilter) new SuffixFileFilter(".class"))) {
            // strip the leading directory
            String binaryName = file.getPath().substring(basePathLength);
            binaryName = pathToBinary(binaryName);
            binaryNames.add(binaryName);
        }

    } else {
        try (ZipFile jar = new ZipFile(dirOrJar)) {
            for (Enumeration entries = jar.entries(); entries.hasMoreElements();) {
                String binaryName = ((ZipEntry) entries.nextElement()).getName();
                if (!binaryName.endsWith(".class")) { // we only need classes
                    continue;
                }
                if (binaryName.startsWith(packagePath)) {
                    binaryName = pathToBinary(binaryName);
                    binaryNames.add(binaryName);
                }
            }
        }
    }

    return binaryNames;
}

From source file:org.openscore.lang.compiler.CompileOperationTest.java

@Test
public void testPreCompileOperationBasic() throws Exception {
    URL resource = getClass().getResource("/check_Weather.sl");
    Executable operation = compiler.preCompile(SlangSource.fromFile(resource.toURI()));

    Assert.assertNotNull("preCompiledMetaData is null", operation);
    Assert.assertEquals("Operation name is wrong", "check_Weather", operation.getName());
    Assert.assertEquals("Operation namespace is wrong", "user.ops", operation.getNamespace());
    Assert.assertEquals("There is a different number of operation inputs than expected", 1,
            operation.getInputs().size());
    Assert.assertEquals("There is a different number of operation outputs than expected", 2,
            operation.getOutputs().size());
    Assert.assertEquals("There is a different number of operation results than expected", 1,
            operation.getResults().size());
    Assert.assertEquals("There is a different number of operation dependencies than expected", 0,
            operation.getDependencies().size());
}

From source file:com.github.jknack.handlebars.maven.I18nJsPlugin.java

/**
 * List all the resource bundle found in the classpath.
 *
 * @param bundle The bundle's name.//from   ww  w . j a v  a2s. com
 * @param classpath The project classpath.
 * @return Some resource bundles.
 * @throws Exception If something goes wrong.
 */
private List<File> bundles(final String bundle, final URL[] classpath) throws Exception {
    Set<File> bundles = new LinkedHashSet<File>();
    for (URL url : classpath) {
        File dir = new File(url.toURI());
        bundles.addAll(FileUtils.getFiles(dir, bundle.replace(".", FileUtils.FS) + "*.properties", null));
    }
    return new ArrayList<File>(bundles);
}

From source file:com.github.ukase.config.UkaseSettings.java

private URI getClassPathUri() {
    try {//from w w w . j  a  v a 2 s .c om
        URL classPath = getClass().getClassLoader().getResource(".");
        if (classPath == null) {
            throw new IllegalStateException("ClassPath is null");
        }
        return classPath.toURI();
    } catch (URISyntaxException e) {
        throw new IllegalStateException("Cannot resolve ClassPath");
    }
}

From source file:com.garyclayburg.attributes.AttributeServiceSpringTest.java

@Before
public void setUp() throws IOException, URISyntaxException {
    log.debug("Running test setUp: " + testName.getMethodName());
    URL groovyURL = this.getClass().getClassLoader().getResource("groovies/emptyscript.groovy");

    assert groovyURL != null;

    String scriptRoot = new File(groovyURL.toURI()).getParentFile().getPath();
    scriptRunner.setRoot(new String[] { scriptRoot });

    attributeService.setScriptRunner(scriptRunner);

    luke = new User();
    luke.setFirstname("Luke");
    luke.setLastname("Bryan");
    luke.setId("11223345");
    auditedUserRepo.save(luke);//  w  w  w.  jav a  2s  .  c o m

}

From source file:io.cloudslang.lang.compiler.CompileOperationTest.java

@Test
public void testPreCompileOperationBasic() throws Exception {
    URL resource = getClass().getResource("/check_Weather.sl");
    Executable operation = compiler.preCompile(SlangSource.fromFile(resource.toURI()));

    Assert.assertNotNull("preCompiledMetaData is null", operation);
    Assert.assertEquals("Operation name is wrong", "check_Weather", operation.getName());
    Assert.assertEquals("Operation namespace is wrong", "user.ops", operation.getNamespace());
    Assert.assertEquals("There is a different number of operation inputs than expected", 1,
            operation.getInputs().size());
    Assert.assertEquals("There is a different number of operation outputs than expected", 2,
            operation.getOutputs().size());
    Assert.assertEquals("There is a different number of operation results than expected", 1,
            operation.getResults().size());
    Assert.assertEquals("There is a different number of operation dependencies than expected", 0,
            operation.getExecutableDependencies().size());
}

From source file:functionaltests.workflow.TestJobLegacySchemas.java

@Test
public void testJobLegacySchemas() throws Throwable {
    for (URL jobDescriptor : jobDescriptors) {
        log("Testing submission of job descriptor : " + jobDescriptor);
        prepareDataspaceFolder();/*  w w  w  .  j a  v  a  2 s.c  o m*/
        String jobDescPath = new File(jobDescriptor.toURI()).getAbsolutePath();
        Job testJob = JobFactory.getFactory().createJob(jobDescPath);
        // This line prints the debug information of the job, checking that no toString method produces a NPE
        log(testJob.display());
        schedulerHelper.testJobSubmission(jobDescPath);
    }
}

From source file:com.omertron.bgg.tools.HttpTools.java

/**
 * GET data from the URL//from w ww  .j av  a  2s.c  o  m
 *
 * @param url URL to use in the request
 * @return String content
 * @throws BggException Custom exception containing failure code
 */
public String getRequest(final URL url) throws BggException {
    try {
        HttpGet httpGet = new HttpGet(url.toURI());
        httpGet.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON);
        DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET);
        long retryCount = 0L;

        // If we have a 429 response, wait and try again
        while (response.getStatusCode() == STATUS_TOO_MANY_REQUESTS && retryCount++ <= RETRY_MAX) {
            delay(retryCount);

            // Retry the request
            response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET);
        }

        return validateResponse(response, url);
    } catch (URISyntaxException | IOException ex) {
        throw new BggException(ApiExceptionType.CONNECTION_ERROR, null, url, ex);
    } catch (RuntimeException ex) {
        throw new BggException(ApiExceptionType.HTTP_503_ERROR, "Service Unavailable", url, ex);
    }
}