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.qualogy.qafe.bind.io.FileLocation.java

/**
 * this class takes the root argument if not empty
 * and adds it to this.path//from  w  w  w.j a  v a2  s .com
 *
 * protocol http is supported
 *
 * @param root
 * @return
 */
// CHECKSTYLE.OFF: CyclomaticComplexity
public URI toURI() {
    if (this.uri == null) {
        String path = location;

        if (!StringUtils.isEmpty(root) && !root.endsWith("/") && !root.endsWith("\\"))//add File.separator @ end
            root += File.separator;

        path = ((root != null) ? root : "") + ((location != null) ? location : "");

        if (File.separatorChar == '\\') {
            path = path.replace('\\', '/');
        }

        if (path.startsWith(SCHEME_HTTP + COMMON_SCHEME_DELIM)) {
            try {
                URL url = new URL(path);
                this.uri = url.toURI();
            } catch (MalformedURLException e) {
                throw new BindException(e);
            } catch (URISyntaxException e) {
                throw new BindException(e);
            }
        }
        if (path.startsWith(SCHEME_FILE)) {
            try {
                uri = new URI(path);
            } catch (URISyntaxException e) {
                throw new BindException(e);
            }
        } else {
            File file = StringUtils.isEmpty(root) ? new File(((location != null) ? location : ""))
                    : new File(root, ((location != null) ? location : ""));
            if (file.exists()) {
                this.uri = file.toURI();
            }
        }
    }
    return this.uri;
}

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

private void testPutGetScript(String script) throws IOException, URISyntaxException {
    setupLogging();/*  w  w  w .  j  a  v  a  2  s . c  o m*/
    DistributedFileSystem fileSystem = miniDFSCluster.getFileSystem();
    Path dir = new Path("/user/guest/example");
    fileSystem.delete(dir, true);
    fileSystem.mkdirs(dir, new FsPermission("777"));
    fileSystem.setOwner(dir, "guest", "users");
    Binding binding = new Binding();
    binding.setProperty("gateway", driver.getClusterUrl());
    URL readme = driver.getResourceUrl("README");
    File file = new File(readme.toURI());
    System.out.println(file.exists());
    binding.setProperty("file", file.getAbsolutePath());
    GroovyShell shell = new GroovyShell(binding);
    shell.evaluate(driver.getResourceUrl(script).toURI());
    String status = (String) binding.getProperty("status");
    assertNotNull(status);
    System.out.println(status);
    String fetchedFile = (String) binding.getProperty("fetchedFile");
    assertNotNull(fetchedFile);
    System.out.println(fetchedFile);
    assertThat(fetchedFile, containsString("README"));
}

From source file:gov.nih.nci.cacis.ip.mirthconnect.CanonicalModelProcessorMCIntegrationTest.java

@Test
public void failSchemaValidation() throws Exception {

    final URL url = getClass().getClassLoader().getResource("CMP_invalid_schema_soap.xml");
    String request = FileUtils.readFileToString(new File(url.toURI()));
    final Node res = invoke(ADDRESS, SoapTransportFactory.TRANSPORT_ID, request.getBytes());
    assertNotNull(res);/*from ww  w .  j  a  v a 2s  . c  o  m*/

}

From source file:io.cloudslang.lang.compiler.modeller.transformers.OutputsTransformerTest.java

@Before
public void init() throws URISyntaxException {
    URL resource = getClass().getResource("/operation_with_data.sl");
    ParsedSlang file = yamlParser.parse(SlangSource.fromFile(new File(resource.toURI())));
    Map op = file.getOperation();
    outputsMap = (List) op.get(SlangTextualKeys.OUTPUTS_KEY);
}

From source file:es.logongas.iothome.agent.http.Http.java

public Object post(URL url, Object data) {
    try {/*  w  ww .  j a  va2 s. c o  m*/

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost postRequest = new HttpPost(url.toURI());

        StringEntity input = new StringEntity(objectMapper.writeValueAsString(data));
        input.setContentType("application/json");
        postRequest.setEntity(input);

        HttpResponse response = httpClient.execute(postRequest);
        String output = inputStreamToString(response.getEntity().getContent());

        if (response.getStatusLine().getStatusCode() != 201) {
            throw new RuntimeException(
                    "Failed : HTTP error code : " + response.getStatusLine().getStatusCode() + "\n" + output);
        }

        httpClient.getConnectionManager().shutdown();

        return objectMapper.readValue(output, data.getClass());

    } catch (Exception ex) {

        throw new RuntimeException(ex);

    }
}

From source file:com.photon.maven.plugins.android.AbstractAndroidMojoTest.java

public void givenAndroidManifestWithoutInstrumentationThenInstrumentationRunnerIsNotFound()
        throws MalformedURLException, URISyntaxException, MojoExecutionException {
    final URL url = this.getClass().getResource("AndroidManifestWithoutInstrumentation.xml");
    final URI uri = url.toURI();
    final File file = new File(uri);
    final String foundInstrumentationRunner = androidMojo.extractInstrumentationRunnerFromAndroidManifest(file);
    Assert.assertNull(foundInstrumentationRunner);
}

From source file:com.vsct.dt.strowgr.admin.nsq.payload.PayloadTest.java

private void assertSerialization(Object message, String file) throws IOException, URISyntaxException {
    String result = mapper/*from  w w  w .j  a  va2  s  .  co  m*/
            .writer(new DefaultPrettyPrinter().withArrayIndenter(new DefaultPrettyPrinter.FixedSpaceIndenter()))
            .writeValueAsString(message);

    URL resource = getClass().getClassLoader().getResource(file);
    String expected = new String(Files.readAllBytes(Paths.get(resource.toURI())));
    assertEquals(expected.replaceAll("\r\n", "\n"), result.replaceAll("\r\n", "\n"));
}

From source file:hudson.model.UpdateSiteTest.java

private String getResource(String resourceName) throws IOException {
    try {/*from   w w  w.j  a  v a  2 s  .c  o m*/
        URL url = UpdateSiteTest.class.getResource(resourceName);
        return (url != null) ? FileUtils.readFileToString(new File(url.toURI())) : null;
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:com.garyclayburg.data.ProvisionServiceTest.java

@Before
public void setUp() throws Exception {
    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 scriptRunner = new ScriptRunner();
    scriptRunner.setRoot(new String[] { scriptRoot });

    attributeService.setScriptRunner(scriptRunner);
}

From source file:org.apache.wink.test.mock.SpringAwareTestCase.java

/**
 * @return application context path, override to change the application
 *         context path construction/*from w  w w. j  a v a  2s  . c  o  m*/
 */
private String getApplicationContextPath() {
    ArrayList<String> contextList = new ArrayList<String>();

    List<String> additionalContextNames = getAdditionalContextNames();
    if (!additionalContextNames.isEmpty()) {
        contextList.addAll(additionalContextNames);
    }

    try {
        String classPathName = getPackagePath() + File.separator + getClass().getSimpleName() + "Context.xml";

        URL resource = getClass().getClassLoader().getResource(classPathName);
        if (resource != null) {
            File file = new File(resource.toURI());
            if (file.isFile()) {
                contextList.add(classPathName);
            }
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    StringBuilder buf = new StringBuilder(contextList.get(0));
    for (int i = 1; i < contextList.size(); ++i) {
        buf.append(',');
        buf.append(contextList.get(i));
    }
    return buf.toString();

}