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.callimachusproject.rdfa.test.RDFaGenerationTest.java

public static TestSuite suite() throws URISyntaxException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL path = cl.getResource(test_dir);
    File testDir = new File(path.toURI());
    if (testDir.exists() && testDir.isDirectory()) {
        TestSuite suite = listCases(testDir);
        suite.setName(RDFaGenerationTest.class.getName());
        return suite;
    }/*from   www.  jav a 2s  .  co m*/
    return new TestSuite(RDFaGenerationTest.class.getName());
}

From source file:com.thinkbiganalytics.KyloVersionUtil.java

private static String getBuildVersionString() {
    if (StringUtils.isBlank(versionString)) {
        String currentVersion = null;
        Properties prop = new Properties();
        String versionFile = "version.txt";

        InputStream in = KyloVersionUtil.class.getClassLoader().getResourceAsStream(versionFile);
        URL url = KyloVersionUtil.class.getClassLoader().getResource(versionFile);
        if (in != null) {
            try {
                try {
                    log.info("finding version information from {} ", url.toURI().getPath().toString());
                } catch (Exception e) {

                }//from   w w  w  . j  a  va 2  s . co m
                prop.load(in);
                currentVersion = prop.getProperty("version");
                buildTimestamp = prop.getProperty("build.date");

                log.info("loaded Kylo version file: {}  build Time: {}", currentVersion, buildTimestamp);
            } catch (IOException e) {

            }
        }
        versionString = currentVersion;
    }
    return versionString;

}

From source file:de.betterform.agent.web.WebFactory.java

/**
 * get the absolute file path for a given relative path in the webapp. Handles some differences in server behavior
 * with the execution of context.getRealPath on various servers/operating systems
 *
 * @param path    a path relative to the context root of the webapp
 * @param context the servletcontext/*  ww w .j a va  2s .co  m*/
 * @return the absolute file path for given relative webapp path
 */
public static String getRealPath(String path, ServletContext context) throws XFormsConfigException {
    if (path == null) {
        path = "/";
    }
    if (!path.startsWith("/")) {
        path = "/" + path;
    }
    try {
        URI resourceURI = null;
        String computedRealPath = null;
        URL rootURL = Thread.currentThread().getContextClassLoader().getResource("/");
        URL resourceURL = context.getResource(path);

        if (rootURL != null) {
            resourceURI = rootURL.toURI();
        }

        if (resourceURI != null && resourceURI.getScheme().equalsIgnoreCase("file")) {
            String resourcePath = rootURL.getPath();
            String rootPath = new File(resourcePath).getParentFile().getParent();
            computedRealPath = new File(rootPath, path).getAbsolutePath();
        } else if (resourceURL != null) {
            computedRealPath = new File(resourceURL.toExternalForm(), path).getAbsolutePath();
        } else {
            String resourcePath = context.getRealPath("/");
            computedRealPath = new File(resourcePath, path).getAbsolutePath();
        }
        return java.net.URLDecoder.decode(computedRealPath, StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        throw new XFormsConfigException("path could not be resolved: " + path, e);
    } catch (URISyntaxException e) {
        throw new XFormsConfigException("path could not be resolved: " + path, e);
    } catch (MalformedURLException e) {
        throw new XFormsConfigException("path could not be resolved: " + path, e);
    }
}

From source file:android.databinding.tool.store.LayoutFileParser.java

public static File urlToFile(URL url) throws MalformedURLException {
    try {/*from   w  ww  . j av  a  2s . c o m*/
        return new File(url.toURI());
    } catch (IllegalArgumentException e) {
        MalformedURLException ex = new MalformedURLException(e.getLocalizedMessage());
        ex.initCause(e);
        throw ex;
    } catch (URISyntaxException e) {
        return new File(url.getPath());
    }
}

From source file:org.kie.smoke.wb.util.RestUtil.java

private static String createBaseUriString(URL deploymentUrl, String relativeUrl) {
    String uriStr = null;/*from   w  w  w  .  j  av a2s . c o m*/
    try {
        uriStr = deploymentUrl.toURI() + relativeUrl;
    } catch (URISyntaxException urise) {
        logAndFail("Invalid uri :" + deploymentUrl.toString(), urise);
    }
    return uriStr;
}

From source file:org.kie.remote.tests.base.RestUtil.java

private static String createBaseUriString(URL deploymentUrl, String relativeUrl) {
    String uriStr = null;/*from   w w w.j  a v  a 2s  .c om*/
    try {
        uriStr = deploymentUrl.toURI() + relativeUrl;
    } catch (URISyntaxException urise) {
        failAndLog("Invalid uri :" + deploymentUrl.toString(), urise);
    }
    return uriStr;
}

From source file:org.opencastproject.util.IoSupport.java

/**
 * Writes the contents variable to the {@code URL}. Note that the URL must be a local {@code URL}.
 *
 * @param file/* w  w w  . j a va  2 s.  c o  m*/
 *         The {@code URL} of the local file you wish to write to.
 * @param contents
 *         The contents of the file you wish to create.
 * @throws URISyntaxException
 */
public static void writeUTF8File(URL file, String contents) throws IOException {
    try {
        writeUTF8File(new File(file.toURI()), contents);
    } catch (URISyntaxException e) {
        throw new IOException("Couldn't parse the URL", e);
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.PropertiesTest.java

private static List<String> getProperties(final BrowserVersion browserVersion) throws Exception {
    final URL url = PropertiesTest.class.getClassLoader()
            .getResource("objects/properties." + browserVersion.getNickname() + ".txt");
    return FileUtils.readLines(new File(url.toURI()));
}

From source file:io.Tools.java

/**
 * Tested method to get a PDB file from path
 * The chemcomp are automatically downloaded
 *
 * @param url//w  ww  . j  a  v a 2 s . c o  m
 * @throws ParsingConfigFileException
 * @throws IOException
 */
private static Structure getStructure(URL url)
        throws ParsingConfigFileException, IOException, ExceptionInIOPackage {

    AlgoParameters algoParameters = Tools.generateModifiedAlgoParametersForTestWithTestFolders();

    Path path = null;
    try {
        path = Paths.get(url.toURI());
    } catch (URISyntaxException e1) {
        assertTrue(false);
    }
    Structure structure = null;
    BiojavaReaderIfc reader = new BiojavaReader(algoParameters);
    structure = reader.read(path.toFile().getAbsolutePath(), algoParameters.getPATH_TO_CHEMCOMP_FOLDER())
            .getValue();
    return structure;
}

From source file:com.hp.application.automation.tools.octane.configuration.ConfigurationParser.java

public static MqmProject parseUiLocation(String uiLocation) throws FormValidation {
    try {//  ww w .  j  a v a2  s  .c o  m
        URL url = new URL(uiLocation);
        String location;
        int contextPos = uiLocation.indexOf("/ui");
        if (contextPos < 0) {
            throw FormValidation.errorWithMarkup(markup("red", Messages.ApplicationContextNotFound()));
        } else {
            location = uiLocation.substring(0, contextPos);
        }
        List<NameValuePair> params = URLEncodedUtils.parse(url.toURI(), "UTF-8");
        for (NameValuePair param : params) {
            if (param.getName().equals(PARAM_SHARED_SPACE)) {
                String[] sharedSpaceAndWorkspace = param.getValue().split("/");
                // we are relaxed and allow parameter without workspace in order not to force user to makeup
                // workspace value when configuring manually or via config API and not via copy & paste
                if (sharedSpaceAndWorkspace.length < 1 || StringUtils.isEmpty(sharedSpaceAndWorkspace[0])) {
                    throw FormValidation.errorWithMarkup(markup("red", Messages.UnexpectedSharedSpace()));
                }
                return new MqmProject(location, sharedSpaceAndWorkspace[0]);
            }
        }
        throw FormValidation.errorWithMarkup(markup("red", Messages.MissingSharedSpace()));
    } catch (MalformedURLException e) {
        throw FormValidation.errorWithMarkup(markup("red", Messages.ConfigurationUrInvalid()));
    } catch (URISyntaxException e) {
        throw FormValidation.errorWithMarkup(markup("red", Messages.ConfigurationUrInvalid()));
    }
}