Example usage for java.io File toURI

List of usage examples for java.io File toURI

Introduction

In this page you can find the example usage for java.io File toURI.

Prototype

public URI toURI() 

Source Link

Document

Constructs a file: URI that represents this abstract pathname.

Usage

From source file:com.msd.gin.halyard.tools.HalyardUpdateTest.java

@BeforeClass
public static void setup() throws Exception {
    File rf = File.createTempFile("HalyardUpdateTest", "");
    rf.delete();/*from w  ww .ja v a  2 s .co m*/
    rf.mkdirs();
    ROOT = rf.toURI().toURL().toString();
    if (!ROOT.endsWith("/")) {
        ROOT = ROOT + "/";
    }
    ValueFactory vf = SimpleValueFactory.getInstance();
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), TABLE, true, 0, true, 0, null);
    sail.initialize();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/pred"),
                    vf.createIRI("http://whatever/obj" + j));
        }
    }
    sail.commit();
    sail.shutDown();
    HalyardUpdate.conf = HBaseServerTestInstance.getInstanceConfig();
}

From source file:io.apiman.common.config.ConfigFileConfiguration.java

/**
 * Returns a URL to a file with the given name inside the given directory.
 *//*  w ww.j  a  va2  s .  c o m*/
protected static URL findConfigUrlInDirectory(File directory, String configName) {
    if (directory.isDirectory()) {
        File cfile = new File(directory, configName);
        if (cfile.isFile()) {
            try {
                return cfile.toURI().toURL();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return null;
}

From source file:com.liferay.blade.tests.BladeCLI.java

public static String installBundle(File file) throws Exception {
    String output = execute("sh", "install", file.toURI().toString());

    String bundleID = output.substring(output.length() - 3);

    if (output.contains("Failed") || output.contains("IOException")) {
        throw new Exception(output);
    }//from  ww w .  ja v  a 2s . co  m

    return bundleID;
}

From source file:gov.va.vinci.leo.CommandLineClient.java

/**
 * Parse the groovy config files, and return the listener objects that are defined in them.
 *
 * @param configs   the groovy config files to slurp
 * @return   the list of listeners that are defined in the groovy configs.
 * @throws MalformedURLException if the configuration file url that was set is invalid.
 *//* w  w w  .  j  a va 2  s.  c  om*/
public static List<UimaAsBaseCallbackListener> getListeners(File... configs) throws MalformedURLException {
    ConfigSlurper configSlurper = new ConfigSlurper();
    List<UimaAsBaseCallbackListener> listeners = new ArrayList<UimaAsBaseCallbackListener>();

    for (File config : configs) {
        ConfigObject configObject = configSlurper.parse(config.toURI().toURL());
        if (configObject.get("listener") != null) {
            listeners.add((UimaAsBaseCallbackListener) configObject.get("listener"));
        }
    }
    return listeners;
}

From source file:marytts.tools.install.LicenseRegistry.java

/**
 * For the license identified by the given URL, return the URL of a local file providing the same content as the given URL. If
 * the license has not been downloaded yet, it will be now.
 * //from www .  j av  a  2  s  .c  o  m
 * @param licenseURL
 *            the remote URL of the license, serving as the license's identifier.
 * @return the URL of a local file from which the license text can be read even if there is no internet connection.
 */
public static URL getLicense(URL licenseURL) {
    long startT = System.currentTimeMillis();
    if (remote2local == null) {
        loadLocalLicenses();
    }
    assert remote2local != null;
    if (!remote2local.containsKey(licenseURL)) {
        downloadLicense(licenseURL);
    }
    String localFilename = remote2local.get(licenseURL);
    File downloadDir = new File(System.getProperty("mary.downloadDir", "."));
    File localFile = new File(downloadDir, localFilename);
    try {
        URL localURL = localFile.toURI().toURL();
        System.out.println("Lookup took " + (System.currentTimeMillis() - startT) + " ms");
        return localURL;
    } catch (MalformedURLException e) {
        System.err.println("Cannot create URL from local file " + localFile.getAbsolutePath());
        e.printStackTrace();
    }
    return null;
}

From source file:com.net2plan.utils.HTMLUtils.java

/**
 * Converts an XML file to a formatted HTML output via an XSLT definition.
 * //  www  . j av  a2s.  c  o  m
 * @param xml String containing an XML file
 * @param xsl File containing an XSLT definition
 * @return Formatted HTML output
 */
public static String getHTMLFromXML(String xml, File xsl) {
    try {
        URL url = xsl.toURI().toURL();
        return getHTMLFromXML(xml, url);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:com.net2plan.utils.HTMLUtils.java

/**
 * <p>Returns the HTML text from a given file. It is a wrapper method for {@link #getHTMLFromURL getHTMLFromURL()}.</p>
 *
 * @param file A valid file//  w  w  w .  j a  v a 2s  .  c om
 * @return A HTML String
 */
public static String getHTMLFromFile(File file) {
    try {
        URL url = file.toURI().toURL();
        return getHTMLFromURL(url);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:io.apiman.common.config.ConfigFileConfiguration.java

/**
 * Discover the location of the apiman.properties (for example) file by checking
 * in various likely locations.//  w w  w .ja  v a 2s  .c o m
 */
private static URL discoverConfigFileUrl(String configFileName, String customConfigPropertyName) {
    URL rval;

    // User Defined
    ///////////////////////////////////
    String userConfig = System.getProperty(customConfigPropertyName);
    if (userConfig != null) {
        // Treat it as a URL
        try {
            rval = new URL(userConfig);
            return rval;
        } catch (Exception t) {
        }
        // Treat it as a file
        try {
            File f = new File(userConfig);
            if (f.isFile()) {
                rval = f.toURI().toURL();
                return rval;
            }
        } catch (Exception t) {
        }
        throw new RuntimeException(
                "Apiman configuration provided at [" + userConfig + "] but could not be loaded."); //$NON-NLS-1$ //$NON-NLS-2$
    }

    // Wildfly/EAP
    ///////////////////////////////////
    String jbossConfigDir = System.getProperty("jboss.server.config.dir"); //$NON-NLS-1$
    String jbossConfigUrl = System.getProperty("jboss.server.config.url"); //$NON-NLS-1$
    if (jbossConfigDir != null) {
        File dirFile = new File(jbossConfigDir);
        rval = findConfigUrlInDirectory(dirFile, configFileName);
        if (rval != null) {
            return rval;
        }
    }
    if (jbossConfigUrl != null) {
        File dirFile = new File(jbossConfigUrl);
        rval = findConfigUrlInDirectory(dirFile, configFileName);
        if (rval != null) {
            return rval;
        }
    }

    // Apache Tomcat
    ///////////////////////
    String tomcatHomeDir = System.getProperty("catalina.home"); //$NON-NLS-1$
    if (tomcatHomeDir != null) {
        File dirFile = new File(tomcatHomeDir, "conf"); //$NON-NLS-1$
        rval = findConfigUrlInDirectory(dirFile, configFileName);
        if (rval != null) {
            return rval;
        }
    }

    // If not found, use an empty file.
    ////////////////////////////////////////
    return ConfigFileConfiguration.class.getResource("empty.properties"); //$NON-NLS-1$
}

From source file:com.katsu.dwm.reflection.JarUtils.java

/**
 * Return as stream a resource in a jar/*  www  .j  a v a2s .  c  o m*/
 * @param jar
 * @param resource 
 */
public static InputStream getResourceAsStream(File jar, String resource) {
    try {
        URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { jar.toURI().toURL() }, null);
        return urlClassLoader.getResourceAsStream(resource);
    } catch (Exception e) {
        logger.error(e);
    }
    return null;
}

From source file:net.refractions.udig.document.source.ShpDocUtils.java

/**
 * Gets the relative path with the url as the parent path and the absolute path as the child
 * path./*from  ww w . j  a  v  a2  s . c  o m*/
 * 
 * @param url
 * @param absolutePath
 * @return relative path
 */
public static String getRelativePath(URL url, String absolutePath) {
    if (absolutePath != null && absolutePath.trim().length() > 0) {
        try {
            final File parentFile = new File(new URI(url.toString()));
            final File parentDir = parentFile.getParentFile();
            final File childFile = new File(absolutePath);
            return parentDir.toURI().relativize(childFile.toURI()).getPath();
        } catch (URISyntaxException e) {
            // Should not happen as shapefile should be a valid file
            e.printStackTrace();
        }
    }
    return null;
}