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:Main.java

@Override
public void start(Stage primaryStage) {
    try {//  w ww  .ja va  2s  . c om
        File file = new File("C:/Users/abc/myphoto.jpg");
        String localUrl = file.toURI().toURL().toString();
        // don't load in the background
        Image localImage = new Image(localUrl, false);

        String remoteUrl = "http://java2s.com/style/demo/Firefox.png";
        // load in the background
        Image remoteImage = new Image(remoteUrl, true);

        System.out.println(localUrl);
        System.out.println(remoteUrl);

    } catch (MalformedURLException ex) {
        // error
    }
}

From source file:io.siddhi.doc.gen.core.utils.DocumentationUtils.java

/**
 * Returns the extension extension meta data
 * Gets the meta data from the siddhi manager
 *
 * @param targetDirectoryPath The path of the target directory of the maven module containing extensions
 * @param logger              The maven plugin logger
 * @return NamespaceMetaData namespace meta data list
 * @throws MojoFailureException   If this fails to access project dependencies
 * @throws MojoExecutionException If the classes directory from which classes are loaded is invalid
 *///from   ww  w .  j a va2s .co m
public static List<NamespaceMetaData> getExtensionMetaData(String targetDirectoryPath,
        List<String> runtimeClasspathElements, Log logger) throws MojoFailureException, MojoExecutionException {
    List<NamespaceMetaData> namespaceMetaDataList = new ArrayList<NamespaceMetaData>();
    int urlCount = runtimeClasspathElements.size() + 1; // +1 to include the module's target/classes folder

    // Creating a list of URLs with all project dependencies
    URL[] urls = new URL[urlCount];
    for (int i = 0; i < runtimeClasspathElements.size(); i++) {
        try {
            urls[i] = new File(runtimeClasspathElements.get(i)).toURI().toURL();
        } catch (MalformedURLException e) {
            throw new MojoFailureException(
                    "Unable to access project dependency: " + runtimeClasspathElements.get(i), e);
        }
    }

    File classesDirectory = new File(targetDirectoryPath + File.separator + Constants.CLASSES_DIRECTORY);
    try {
        // Adding the generated classes to the class loader
        urls[urlCount - 1] = classesDirectory.toURI().toURL();
        ClassLoader urlClassLoader = AccessController
                .doPrivileged((PrivilegedAction<ClassLoader>) () -> new URLClassLoader(urls,
                        Thread.currentThread().getContextClassLoader()));
        // Getting extensions from all the class files in the classes directory
        addExtensionInDirectory(classesDirectory, classesDirectory.getAbsolutePath(), urlClassLoader,
                namespaceMetaDataList, logger);
    } catch (MalformedURLException e) {
        throw new MojoExecutionException("Invalid classes directory: " + classesDirectory.getAbsolutePath(), e);
    }
    for (NamespaceMetaData aNamespaceMetaData : namespaceMetaDataList) {
        for (List<ExtensionMetaData> extensionMetaData : aNamespaceMetaData.getExtensionMap().values()) {
            Collections.sort(extensionMetaData);
        }
    }
    Collections.sort(namespaceMetaDataList);
    return namespaceMetaDataList;
}

From source file:com.aionemu.commons.scripting.impl.javacompiler.JavaSourceFromFile.java

/**
 * Construct a JavaFileObject of the given kind and with the given File.
 *
 * @param file the file with source of this file object
 * @param kind the kind of this file object
 *///from  www.  j  av  a  2s .  c  o  m
public JavaSourceFromFile(File file, Kind kind) {
    super(file.toURI(), kind);
}

From source file:ca.sqlpower.dao.session.FileConverter.java

@Override
public String convertToSimpleType(File convertFrom, Object... additionalInfo) {
    return convertFrom.toURI().toString();
}

From source file:com.github.born2snipe.maven.log.config.ConfigSerializer.java

public Config load(File file) {
    try {//from w w w . j  av a  2  s.c o m
        return loadUrl(file.toURI().toURL());
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.minecraftforge.fml.relauncher.CoreModManager.java

private static void handleCascadingTweak(File coreMod, JarFile jar, String cascadedTweaker,
        LaunchClassLoader classLoader, Integer sortingOrder) {
    try {// w w w. j  ava2s .c  o  m
        // Have to manually stuff the tweaker into the parent classloader
        if (ADDURL == null) {
            ADDURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            ADDURL.setAccessible(true);
        }
        ADDURL.invoke(classLoader.getClass().getClassLoader(), coreMod.toURI().toURL());
        classLoader.addURL(coreMod.toURI().toURL());
        CoreModManager.tweaker.injectCascadingTweak(cascadedTweaker);
        tweakSorting.put(cascadedTweaker, sortingOrder);
    } catch (Exception e) {
        FMLRelaunchLog.log(Level.INFO, e, "There was a problem trying to load the mod dir tweaker %s",
                coreMod.getAbsolutePath());
    }
}

From source file:com.stehno.sanctuary.core.remote.InMemoryRemoteStore.java

private String extractRoot(File rootDirectory) {
    return rootDirectory.toURI().toString();
}

From source file:dtool.engine.modules.BundleModulesVisitor.java

protected void visitPotentialModuleFile(File potentialFile, File importFolder) {
    String relPath = importFolder.toURI().relativize(potentialFile.toURI()).getPath();
    ModuleFullName moduleFullName = ModuleNamingRules.getValidModuleNameOrNull(relPath);
    if (moduleFullName != null) {
        assertTrue(potentialFile.isAbsolute());
        addModuleEntry(moduleFullName, potentialFile);
    }/*from  www  .  j  a  v a2  s  .  c  o  m*/
}

From source file:com.stehno.sanctuary.core.remote.InMemoryRemoteStore.java

private String extractStoreFile(File file, String root) {
    return file.toURI().toString().replace(root, "");
}

From source file:com.textocat.textokit.morph.opencorpora.resource.CachedDictionaryDeserializer.java

public GetDictionaryResult getDictionary(File file) throws Exception {
    URL url = file.toURI().toURL();
    InputStream fileIS = FileUtils.openInputStream(file);
    return getDictionary(url, fileIS);
}