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:au.org.ala.delta.intkey.model.DisplayInputTest.java

@Test
public void testDisplayInput() throws Exception {
    IntkeyContext context = loadDataset("/dataset/sample/intkey.ink");

    for (Character ch : context.getDataset().getCharactersAsList()) {
        if (!(ch instanceof MultiStateCharacter)) {
            System.out.println(ch.getCharacterId());
        }/*w  w w . java2s  .  c o m*/
    }

    File tempLogFile = File.createTempFile("DisplayInputTest", null);
    tempLogFile.deleteOnExit();

    context.setLogFile(tempLogFile);

    File tempJournalFile = File.createTempFile("DisplayInputTest", null);
    tempJournalFile.deleteOnExit();

    context.setJournalFile(tempJournalFile);

    URL directiveFileUrl = getClass().getResource("/input/test_directives_file.txt");
    File directivesFile = new File(directiveFileUrl.toURI());

    // first, process the sample file as a preferences file, and ensure that
    // the directive call is not output
    // to the journal or log

    new PreferencesDirective().parseAndProcess(context, directivesFile.getAbsolutePath());

    String logFileAsString = FileUtils.readFileToString(tempLogFile);
    assertFalse(logFileAsString.contains("*DEFINE CHARACTERS preferencestest 1"));

    String journalFileAsString = FileUtils.readFileToString(tempJournalFile);
    assertFalse(journalFileAsString.contains("*DEFINE CHARACTERS preferencestest 1"));

    // now, process the sample file as an input file. As DISPLAY INPUT has
    // not been set to ON,
    // the directive call should still not turn up in the log or journal
    // files

    new FileInputDirective().parseAndProcess(context, directivesFile.getAbsolutePath());

    logFileAsString = FileUtils.readFileToString(tempLogFile);
    assertFalse(logFileAsString.contains("*DEFINE CHARACTERS preferencestest 1"));

    journalFileAsString = FileUtils.readFileToString(tempJournalFile);
    assertFalse(journalFileAsString.contains("*DEFINE CHARACTERS preferencestest 1"));

    // now set DISPLAY INPUT to ON, and process the directives file as an input file again. 

    new DisplayInputDirective().parseAndProcess(context, "ON");

    new FileInputDirective().parseAndProcess(context, directivesFile.getAbsolutePath());

    logFileAsString = FileUtils.readFileToString(tempLogFile);
    assertTrue(logFileAsString.contains("*DEFINE CHARACTERS preferencestest 1"));

    journalFileAsString = FileUtils.readFileToString(tempJournalFile);
    assertTrue(journalFileAsString.contains("*DEFINE CHARACTERS preferencestest 1"));
}

From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.RESTActivityParser.java

@Override
public List<URI> getAdditionalSchemas() {
    URL restXsd = RESTActivityParser.class.getResource(ACTIVITY_XSD);
    try {/*w w  w. j a v  a  2s  .c  o m*/
        return Arrays.asList(restXsd.toURI());
    } catch (Exception e) {
        throw new IllegalStateException("Can't find REST schema " + restXsd);
    }
}

From source file:com.hypersocket.server.handlers.impl.ClasspathContentHandler.java

@Override
public long getLastModified(String path) {
    try {/*from ww w. java2 s. c  o m*/
        URL url = getClass().getResource(classpathPrefix + "/" + path);
        if (log.isDebugEnabled()) {
            log.debug("Processing resource URL " + url.toURI().toString());
        }
        int idx;
        File jarFile;
        if ((idx = url.toURI().toString().indexOf("!")) > -1) {
            jarFile = new File(url.toURI().toString().substring(9, idx));
        } else {
            jarFile = new File(url.toURI());
        }

        if (log.isInfoEnabled()) {
            Date modified = new Date(jarFile.lastModified());
            if (log.isDebugEnabled()) {
                log.debug("Jar file " + jarFile.getAbsolutePath() + " last modified "
                        + HypersocketUtils.formatDateTime(modified));
            }
        }
        return jarFile.lastModified();
    } catch (URISyntaxException e) {
    }

    return System.currentTimeMillis();
}

From source file:org.apache.brooklyn.launcher.BrooklynWebServerTest.java

private String getFile(URL url) {
    try {/*  w  ww . ja  v a  2 s  .  c  o  m*/
        return new File(url.toURI()).getAbsolutePath();
    } catch (URISyntaxException e) {
        throw Exceptions.propagate(e);
    }
}

From source file:com.novoda.imageloader.core.file.util.FileUtilTest.java

@Test
public void shouldCopyStream() throws ImageCopyException, URISyntaxException {
    URL testFile = ClassLoader.getSystemResource("testFile1");
    File from = new File(testFile.toURI());
    assertTrue(from.exists());//from ww  w  . ja v a 2 s.c om
    File to = new File(cacheDir.getAbsolutePath() + "testFile1");

    fileUtil.copy(from, to);

    FileAssert.assertBinaryEquals(from, to);
}

From source file:org.yamj.core.remote.service.GitHubServiceImpl.java

/**
 * Get the date of the last push to a repository
 *
 * @param owner//from ww  w  .j a v a  2  s.c  o  m
 * @param repository
 * @return
 */
@Override
public String pushDate(String owner, String repository) {
    if (StringUtils.isBlank(owner) || StringUtils.isBlank(repository)) {
        LOG.error("Owner '{}' or repository '{}' cannot be blank", owner, repository);
        throw new IllegalArgumentException("Owner or repository cannot be blank");
    }

    String returnDate = "";

    StringBuilder url = new StringBuilder(GH_API);
    url.append(owner).append("/").append(repository);

    try {
        HttpGet httpGet = new HttpGet(url.toString());
        httpGet.setHeader(USER_AGENT, GH_USER_AGENT);
        httpGet.addHeader(ACCEPT, GH_ACCEPT);

        URL newUrl = new URL(url.toString());
        httpGet.setURI(newUrl.toURI());

        String jsonData = httpClient.requestContent(httpGet);

        // This is ugly and a bit of a hack, but I don't need to unmarshal the whole object just for a date.
        int posStart = jsonData.indexOf("pushed_at");
        posStart = jsonData.indexOf("20", posStart);
        int posEnd = jsonData.indexOf('\"', posStart);
        returnDate = jsonData.substring(posStart, posEnd);
        LOG.info("Date: '{}'", returnDate);
    } catch (IOException ex) {
        LOG.warn("Unable to get GitHub information, error: {}", ex.getMessage());
        LOG.warn(ClassTools.getStackTrace(ex));
        return returnDate;
    } catch (RuntimeException ex) {
        LOG.warn("Unable to get GitHub information, error: {}", ex.getMessage());
        LOG.warn(ClassTools.getStackTrace(ex));
        return returnDate;
    } catch (URISyntaxException ex) {
        LOG.warn("Unable to get GitHub information, error: {}", ex.getMessage());
        LOG.warn(ClassTools.getStackTrace(ex));
        return returnDate;
    }
    return returnDate;
}

From source file:org.opendaylight.sfc.sbrest.json.SfstExporterTest.java

private String gatherServiceFunctionSchedulerTypeJsonStringFromFile(String testFileName) {
    String jsonString = null;//from   w w  w  .  jav  a  2  s .  co m

    try {
        URL fileURL = getClass().getResource(testFileName);
        jsonString = TestUtil.readFile(fileURL.toURI(), StandardCharsets.UTF_8);
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }

    for (SfstTestValues sfstTestValue : SfstTestValues.values()) {
        if (jsonString != null) {
            jsonString = jsonString.replaceAll("\\b" + sfstTestValue.name() + "\\b", sfstTestValue.getValue());
        }
    }

    return jsonString;
}

From source file:ch.sourcepond.maven.plugin.jenkins.it.utils.HttpsServerStartupBarrier.java

@Override
protected CloseableHttpClient createClient() throws KeyManagementException, NoSuchAlgorithmException,
        KeyStoreException, CertificateException, IOException, URISyntaxException {
    final URL url = getClass().getResource(KEYSTORE_NAME);
    // Trust own CA and all self-signed certs
    final SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new File(url.toURI()),
            TEST_PASSWORD.toCharArray(), new TrustSelfSignedStrategy()).build();
    // Allow TLSv1 protocol only
    final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,
            SSLConnectionSocketFactory.getDefaultHostnameVerifier());
    final CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

    return httpclient;
}

From source file:com.qualogy.qafe.business.resource.java.spring.SpringContext.java

public String resolveXMLConfigFile(String root, String xmlConfigFile) {
    URI uri = null;/*  w  w  w  .jav  a2s.  c o m*/

    if (!StringUtils.isEmpty(root) && !root.endsWith("/") && !root.endsWith("\\")) {
        root += File.separator;
    }

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

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

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

From source file:com.novoda.imageloader.core.file.util.FileUtilTest.java

@Test
public void shouldCopyStreams() throws FileNotFoundException, URISyntaxException {
    URL testFile = ClassLoader.getSystemResource("testFile1");
    File from = new File(testFile.toURI());
    assertTrue(from.exists());//from   ww  w. j a v  a2s. c o m
    File to = new File(cacheDir.getAbsolutePath() + "testFile3");
    InputStream in = new FileInputStream(from);
    OutputStream out = new FileOutputStream(to);

    fileUtil.copyStream(in, out);

    FileAssert.assertBinaryEquals(from, to);
}