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.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java

public static void updateCaptureFrame(File capturedImgFile, String img_result_html) {

    Photo photo = null;//from w  w  w  .  jav  a 2s.  c  o  m
    try {
        photo = new Photo("IBM Watson predictions for below image", capturedImgFile.toURI().toURL(),
                img_result_html);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    PhotoCaptureFrame.getPhotoesJPanel().add(photo);
    PhotoCaptureFrame.getPhotoesJFrame().repaint();
    PhotoCaptureFrame.getPhotoesJFrame().setVisible(true);
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.tagset.MappingsTest.java

public static void assertTagsetMapping(Collection<File> files) throws IOException {
    for (File file : files) {
        boolean failure = false;
        System.out.printf("== %s ==%n", file.getName());
        MappingProvider mappingProvider = new MappingProvider();
        mappingProvider.setDefault(MappingProvider.LOCATION, file.toURI().toURL().toString());
        mappingProvider.configure();//from ww  w.  j a v a 2s.c o  m
        for (String tag : mappingProvider.getTags()) {
            String typeName = mappingProvider.getTagTypeName(tag);
            try {
                Class.forName(typeName);
            } catch (Throwable e) {
                System.out.printf("%s FAILED: %s %n", tag, e.getMessage());
                failure = true;
            }
        }
        assertFalse(failure);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.core.ResourceFactory.java

public static synchronized ResourceFactory getInstance() throws ResourceLoaderException {
    if (loader == null) {
        List<String> locs = new ArrayList<String>();
        URL resourceXmlUrl = null;

        // Check in workspace
        try {//from   ww  w .  j av a  2 s.com
            File f = new File(getWorkspace(), CONFIG_FILE);
            if (f.isFile()) {
                try {
                    resourceXmlUrl = f.toURI().toURL();
                } catch (MalformedURLException e) {
                    throw new ResourceLoaderException(e);
                }
            }
            locs.add(f.getAbsolutePath());
        } catch (IOException e) {
            locs.add("DKPro workspace not available");
        }

        // Check in classpath
        if (resourceXmlUrl == null) {
            resourceXmlUrl = ResourceFactory.class.getResource(CONFIG_FILE);
            locs.add("Classpath: " + CONFIG_FILE);
        }

        // Check in default file system location
        if (resourceXmlUrl == null && new File(CONFIG_FILE).isFile()) {
            try {
                resourceXmlUrl = new File(CONFIG_FILE).toURI().toURL();
            } catch (MalformedURLException e) {
                throw new ResourceLoaderException(e);
            }
            locs.add(new File(CONFIG_FILE).getAbsolutePath());
        }

        // Bail out if still not found
        if (resourceXmlUrl == null) {
            throw new ResourceLoaderException(
                    "Unable to locate configuration file [" + CONFIG_FILE + "] in " + locs.toString());
        }

        loader = new ResourceFactory(resourceXmlUrl.toString());
    }
    return loader;
}

From source file:com.panet.imeta.core.vfs.KettleVFS.java

public static FileObject getFileObject(String vfsFilename) throws IOException {
    checkHook();/*w  w w. j  av a 2s .c om*/

    try {
        FileSystemManager fsManager = VFS.getManager();

        // We have one problem with VFS: if the file is in a subdirectory of the current one: somedir/somefile
        // In that case, VFS doesn't parse the file correctly.
        // We need to put file: in front of it to make it work.
        // However, how are we going to verify this?
        // 
        // We are going to see if the filename starts with one of the known protocols like file: zip: ram: smb: jar: etc.
        // If not, we are going to assume it's a file.
        //
        boolean relativeFilename = true;
        String[] schemes = VFS.getManager().getSchemes();
        for (int i = 0; i < schemes.length && relativeFilename; i++) {
            if (vfsFilename.startsWith(schemes[i] + ":"))
                relativeFilename = false;
        }

        String filename;
        if (vfsFilename.startsWith("\\\\")) {
            File file = new File(vfsFilename);
            filename = file.toURI().toString();
        } else {
            if (relativeFilename) {
                File file = new File(vfsFilename);
                filename = file.getAbsolutePath();
            } else {
                filename = vfsFilename;
            }
        }

        FileObject fileObject = fsManager.resolveFile(filename);

        return fileObject;
    } catch (IOException e) {
        throw new IOException(
                "Unable to get VFS File object for filename '" + vfsFilename + "' : " + e.toString());
    }
}

From source file:eu.interedition.collatex.tools.CollationPipe.java

private static URL argumentToInput(String arg) throws MalformedURLException {
    final File witnessFile = new File(arg);
    if (witnessFile.exists()) {
        return witnessFile.toURI().normalize().toURL();
    } else {/*from   ww w.jav  a  2 s .  co m*/
        return new URL(arg);
    }
}

From source file:com.teradata.presto.yarn.test.utils.Resources.java

public static Path extractResource(String resourcePath) {
    URL fixScriptResource = Resources.class.getResource(resourcePath);
    File temporaryFile = new File(tempDir, Paths.get(resourcePath).getFileName().toString());
    try {//  w  w w.  j av  a  2  s .  c o  m
        FileUtils.copyURLToFile(fixScriptResource, temporaryFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Paths.get(temporaryFile.toURI());
}

From source file:eu.interedition.collatex.tools.CollationPipe.java

private static InputStream argumentToInputStream(String arg) throws IOException {
    if ("-".equals(arg)) {
        return System.in;
    }/*from www .  j av  a  2 s  .  c  o  m*/
    final File witnessFile = new File(arg);
    if (witnessFile.exists()) {
        return witnessFile.toURI().normalize().toURL().openStream();
    } else {
        return new URL(arg).openStream();
    }
}

From source file:com.codename1.tools.javadoc.sourceembed.javadocsourceembed.Main.java

public static void processFile(File javaSourceFile, File javaDestFile) throws Exception {
    System.out.println("JavaSource Processing: " + javaSourceFile.getName());
    List<String> lines = Files.readAllLines(Paths.get(javaSourceFile.toURI()), CHARSET);
    for (int iter = 0; iter < lines.size(); iter++) {
        String l = lines.get(iter);
        int position = l.indexOf("<script src=\"https://gist.github.com/");
        if (position > -1) {
            String id = l.substring(position + 39);
            id = id.split("/")[1];
            id = id.substring(0, id.indexOf('.'));
            String fileContent = gistCache.get(id);
            if (fileContent != null) {
                lines.add(iter + 1, fileContent);
                iter++;/*from  w  w w  . j a  v  a2s  .c  o  m*/
                continue;
            }

            URL u = new URL("https://api.github.com/gists/" + id + "?client_id=" + CLIENT_ID + "&client_secret="
                    + CLIENT_SECRET);
            try (BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(), CHARSET))) {
                String jsonText = br.lines().collect(Collectors.joining("\n"));
                JSONObject json = new JSONObject(jsonText);
                JSONObject filesObj = json.getJSONObject("files");
                String str = "";
                for (String k : filesObj.keySet()) {
                    JSONObject jsonFileEntry = filesObj.getJSONObject(k);
                    // breaking line to fix the problem with a blank space on the first line
                    String current = "\n" + jsonFileEntry.getString("content");
                    str += current;
                }
                int commentStartPos = str.indexOf("/*");
                while (commentStartPos > -1) {
                    // we just remove the comment as its pretty hard to escape it properly
                    int commentEndPos = str.indexOf("*/");
                    str = str.substring(commentStartPos, commentEndPos + 1);
                    commentStartPos = str.indexOf("/*");
                }

                // allows things like the @Override annotation
                str = "<noscript><pre>{@code " + str.replace("@", "{@literal @}") + "}</pre></noscript>";
                gistCache.put(id, str);
                lines.add(iter + 1, str);
                iter++;
            }
        }
    }
    try (BufferedWriter fw = new BufferedWriter(new FileWriter(javaDestFile))) {
        for (String l : lines) {
            fw.write(l);
            fw.write('\n');
        }
    }
}

From source file:com.elasticbox.jenkins.k8s.cfg.PluginInitializer.java

private static String checkLocalKubernetesToken() {
    File file = new File(KUBE_TOKEN_PATH);
    if (file.exists() && file.canRead()) {
        try {/* w ww. j av a2 s  .  c o m*/
            String token = IOUtils.toString(file.toURI());
            TokenCredentialsImpl kubeServiceToken = new TokenCredentialsImpl(CredentialsScope.SYSTEM,
                    KUBE_SERVICE_TOKEN_ID, "Local Kubernetes service token", Secret.fromString(token));

            SystemCredentialsProvider.getInstance().getCredentials().add(kubeServiceToken);
            SystemCredentialsProvider.getInstance().save();

            return KUBE_SERVICE_TOKEN_ID;

        } catch (IOException excep) {
            LOGGER.warning("Unable to read Kubernetes service token file: " + excep);
        }
    }
    return StringUtils.EMPTY;
}

From source file:com.stacksync.desktop.Stacksync.java

private static void checkOrCreateLogFile() {

    //set the apache derby logs file location
    System.setProperty("derby.system.home",
            env.getDefaultUserConfigDir() + File.separator + Constants.CONFIG_DATABASE_DIRNAME);

    File fileLogConfig = new File(env.getDefaultUserConfigDir() + File.separator + "conf" + File.separator
            + Constants.LOGGING_DEFAULT_FILENAME);
    if (fileLogConfig.exists()) {
        try {/*  www.j a  v a  2 s  .c  o m*/
            String content = FileUtil.readFileToString(fileLogConfig);
            File file = new File(env.getDefaultUserConfigDir().getAbsolutePath() + File.separator + "logs");

            content = content.replace("REPLACED_BY_APPLICATION", file.toURI().toURL().getFile());
            FileUtil.writeFile(content, fileLogConfig);
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
}