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:de.fhg.igd.mapviewer.server.file.MapFileTileProvider.java

/**
 * Creates an URI for an entry in the given jar file
 * //from  www . ja va 2 s.  c om
 * @param jarFile the jar file
 * @param entryName the entry name
 * 
 * @return the {@link URI} representing the entry
 * @throws MalformedURLException if the given file provides no valid url
 */
public static URI getEntryURI(File jarFile, String entryName) throws MalformedURLException {
    return URI.create("jar:" + jarFile.toURI().toURL().toString() + "!/" + entryName); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:com.geewhiz.pacify.utils.FileUtils.java

public static Set<PosixFilePermission> getPosixPermissions(File forFile) {
    if (IS_POSIX) {
        try {//from  ww w.j  a v a 2  s .co  m
            return Files.getPosixFilePermissions(Paths.get(forFile.toURI()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return new TreeSet<PosixFilePermission>();
}

From source file:Main.java

/**
 * Writes the given document to a file (pretty-printed)
 * /* www.  j a  va 2 s  .co m*/
 * @param doc Document to serialize
 * @param file File to write
 */
public static void writeDocument(Document doc, File file) {
    if (doc == null)
        return;
    LSSerializer writer = impl.createLSSerializer();
    writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    writer.writeToURI(doc, file.toURI().toString());
}

From source file:com.microsoft.azure.hdinsight.spark.jobs.JobUtils.java

public static URI getLivyLogPath(@NotNull String rootPath, @NotNull String applicationId) {
    String path = StringHelper.concat(rootPath, File.separator, JobLogFolderName, File.separator,
            applicationId);//from w  w w.j a  v a  2s .  c  o m
    File file = new File(path);
    if (!file.exists()) {
        file.mkdirs();
    }
    return file.toURI();
}

From source file:Main.java

public static File saveToFile(File file, Document document) throws TransformerException {
    // Prepare the DOM document for writing
    Source source = new DOMSource(document);

    // Prepare the output file
    Result result = new StreamResult(file.toURI().getPath());

    // Write the DOM document to the file
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    xformer.setOutputProperty(OutputKeys.INDENT, "yes");
    xformer.transform(source, result);//from w  ww.j  av  a2 s.  co  m

    return file;
}

From source file:com.norconex.commons.lang.ClassFinder.java

private static ClassLoader getClassLoader(File url) {
    try {//from ww  w . ja  v  a  2  s  .  co m
        URL dirURL = url.toURI().toURL();
        return new URLClassLoader(new URL[] { dirURL }, ClassFinder.class.getClassLoader());
    } catch (MalformedURLException e) {
        LOG.error("Invalid classpath: " + url, e);
        return null;
    }
}

From source file:org.stem.ClusterManagerDaemon.java

static URL getConfigUrl() {
    String configPath = System.getProperty(STEM_CONFIG_PROPERTY);
    if (null == configPath)
        configPath = DEFAULT_CONFIG;/*from www  .j a  v  a  2 s  .c  o  m*/

    URL url;

    try {
        File file = new File(configPath);
        url = file.toURI().toURL();
        url.openStream().close();
    } catch (Exception e) {
        ClassLoader loader = ClusterManagerDaemon.class.getClassLoader();
        url = loader.getResource(configPath);
        if (null == url)
            throw new RuntimeException("Cannot load " + configPath + ". Ensure \"" + STEM_CONFIG_PROPERTY
                    + "\" system property is set correctly.");
    }

    return url;
}

From source file:com.apporiented.hermesftp.PluginManager.java

/**
 * Adds a resource to the classpath. Note that the resource is not available before the update
 * method of the classloader is called./*ww  w .  j  av  a 2s  .com*/
 * 
 * @param jarOrPath The resource to add.
 */
public static void addResource(File jarOrPath) {
    try {
        classLoader.addURL(jarOrPath.toURI().toURL());
    } catch (MalformedURLException e) {
        log.error(e);
    }
}

From source file:com.geewhiz.pacify.utils.FileUtils.java

public static void setPosixPermissions(Set<PosixFilePermission> permissions, File forFile) {
    if (!IS_POSIX) {
        return;// w  w  w  .  ja  v a2s.  c o  m
    }

    try {
        Files.setPosixFilePermissions(Paths.get(forFile.toURI()), permissions);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.nava.informa.parsers.FeedParser.java

/**
 * Parse feed presented by file and build channel.
 *
 * @param cBuilder specific channel builder to use.
 * @param aFile    file to read data from.
 * @return parsed channel.// w w w .  jav  a  2 s  .  c om
 * @throws IOException    if IO errors occur.
 * @throws ParseException if parsing is not possible.
 */
public static ChannelIF parse(ChannelBuilderIF cBuilder, File aFile) throws IOException, ParseException {
    URL aURL;
    try {
        aURL = aFile.toURI().toURL();
    } catch (java.net.MalformedURLException e) {
        throw new IOException("File " + aFile + " had invalid URL representation.");
    }
    return parse(cBuilder, new InputSource(aURL.toExternalForm()), aURL);
}