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:deployer.TestUtils.java

public static AppDirs[] makeNumberGits(int number, String baseName) throws GitAPIException {
    List<AppDirs> gits = Lists.newArrayListWithCapacity(number);
    for (int i = 0; i < number; i++) {
        File remoteTestDir = Files.resolve(GIT_TEST_DIR, baseName + "xx" + i + ".git");
        File testDir = Files.resolve(GIT_TEST_DIR, baseName + "xx" + i);
        Files.createDirectories(testDir);
        Git remoteGit = Git.init().setBare(true).setDirectory(remoteTestDir).call();

        Git git = Git.cloneRepository().setURI(remoteTestDir.toURI().toString()).setDirectory(testDir).call();
        gits.add(new AppDirs(remoteGit, git, testDir));
    }//  w w  w .ja va  2  s  .c om
    return gits.toArray(new AppDirs[gits.size()]);
}

From source file:net.sourceforge.czt.gnast.Gnast.java

private static URL toURL(File file) {
    if (file == null) {
        return null;
    }//from w  w  w .  jav a  2  s  . c  om

    try {
        return file.toURI().toURL();
    } catch (MalformedURLException e) {
        throw new GnastException("File " + file + " cannot be converted to URL: " + e.getMessage(), e);
    }
}

From source file:eu.stratosphere.core.testing.GenericTestPlan.java

private static String createTemporaryFile(final String suffix, final String prefix) {
    try {/*from   ww w .j  a v a  2 s  .com*/
        final File tempFile = File.createTempFile(suffix, prefix);
        tempFile.deleteOnExit();
        return tempFile.toURI().toString();
    } catch (final IOException e) {
        throw new IllegalStateException("Cannot create temporary file for prefix " + prefix, e);
    }
}

From source file:net.drgnome.virtualpack.util.Util.java

public static boolean loadJar(File file) {
        ClassLoader loader = _plugin.getClass().getClassLoader();
        if (loader instanceof URLClassLoader) {
            try {
                URLClassLoader cl = (URLClassLoader) loader;
                Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
                m.setAccessible(true);//w  w w . java  2 s  .c o m
                m.invoke(cl, file.toURI().toURL());
            } catch (Exception e) {
                warn();
                e.printStackTrace();
                return false;
            }
        } else {
            warn();
            _log.severe("[VirtualPack] PluginClassLoader not URLClassLoader!");
            return false;
        }
        return true;
    }

From source file:fr.lirmm.yamplusplus.yampponline.YamFileHandler.java

/**
 * TODO: REMOVE? Done by yampp-ls. Convert Skos Ontology to OWL. We are adding
 * the rdf:type owl:Class to every skos:Concept. And
 * skos:broader/skos:narrower are replaced by rdfs:subClassOf. Also adding the
 * triple <http://my_ontology_URI/> rdf:type owl:Ontology And adding
 * rdfs:label for all skos:prefLabel (not really useful because we handle
 * skos:prefLabel)//from   w w w. jav  a2s  .  com
 *
 * @param skosFile
 * @param outputFile
 * @param outputFormat
 * @return String
 */
public static String convertSkosToOwl(File skosFile, File outputFile, String outputFormat) {
    Model model = ModelFactory.createDefaultModel();

    try {
        model.read(skosFile.toURI().toString());
    } catch (Exception e) {
        // Read in TTL if first parsing failed (it waits for RDF/XML)
        model.read(skosFile.toURI().toString(), null, "TTL");
    }

    Property inSchemeProperty = model.getProperty("http://www.w3.org/2004/02/skos/core#inScheme");
    // Add rdf:type owl:Ontology to the namespace URI
    if (model.getNsPrefixURI("") != null) {
        model.createResource(model.getNsPrefixURI("")).addProperty(RDF.type, OWL.Ontology);
    } else if (model.listSubjectsWithProperty(RDF.type,
            model.getResource("http://www.w3.org/2004/02/skos/core#ConceptScheme")).hasNext()) {
        ResIterator skosSchemeIterator = model.listSubjectsWithProperty(RDF.type,
                model.getResource("http://www.w3.org/2004/02/skos/core#ConceptScheme"));
        while (skosSchemeIterator.hasNext()) {
            Resource cls = skosSchemeIterator.next();
            if (cls != null) {
                cls.addProperty(RDF.type, OWL.Ontology);
            }
        }
    } else if (model.listSubjectsWithProperty(inSchemeProperty).hasNext()) {
        // If no base namespace, then we try to take it from skos:inScheme
        ResIterator skosInSchemeIterator = model.listSubjectsWithProperty(inSchemeProperty);
        // Iterate over skos:Concept to add the rdf:type owl:Class to all concepts
        while (skosInSchemeIterator.hasNext()) {
            Resource cls = skosInSchemeIterator.next();
            if (cls != null) {
                Statement stmt = cls.getProperty(inSchemeProperty);
                // Add rdf:type owl:Class triple to the 1st inScheme object found
                model.createResource(stmt.getObject().toString()).addProperty(RDF.type, OWL.Ontology);
                break;
            }
        }
    } else {
        // Define a default ontology URI if nothing found
        model.createResource("http://yamplusplus.lirmm.fr/matching_ontology").addProperty(RDF.type,
                OWL.Ontology);
    }

    //Property hasName = ResourceFactory.createProperty(yourNamespace, "hasName"); // hasName property
    /*Resource owlOntologyResource = model.createResource(RDF.);
    Resource instance2 = model.createResource(instance2Uri);
    <http://ontology.irstea.fr/cropusage/2016/05> rdf:type owl:Ontology ;
            
    // Create statements
    owlOntologyResource.addProperty(RDF.type, class1); // Classification of instance1*/
    ResIterator skosConceptsIterator = model.listSubjectsWithProperty(RDF.type,
            model.getResource("http://www.w3.org/2004/02/skos/core#Concept"));
    // Iterate over skos:Concept to add the rdf:type owl:Class to all concepts
    while (skosConceptsIterator.hasNext()) {
        Resource cls = skosConceptsIterator.next();
        if (cls != null) {
            cls.addProperty(RDF.type, OWL.Class);
        }
    }

    ResIterator skosBroaderIterator = model
            .listSubjectsWithProperty(model.getProperty("http://www.w3.org/2004/02/skos/core#broader"));
    // Iterate over skos:broader properties to add the equivalent with the rdfs:subClassOf property
    while (skosBroaderIterator.hasNext()) {
        List<Resource> broaderResources = new ArrayList();
        List<Resource> narrowerResources = new ArrayList();
        Resource cls = skosBroaderIterator.next();
        if (cls != null) {
            StmtIterator stmts = cls.listProperties();
            while (stmts.hasNext()) {
                // the iterator returns statements: [subject, predicate, object]
                StatementImpl tripleArray = (StatementImpl) stmts.next();
                if (tripleArray.getPredicate().toString()
                        .equals("http://www.w3.org/2004/02/skos/core#broader")) {
                    broaderResources.add(tripleArray.getResource());
                } else if (tripleArray.getPredicate().toString()
                        .equals("http://www.w3.org/2004/02/skos/core#narrower")) {
                    narrowerResources.add(tripleArray.getResource());
                }
            }
            for (Resource broaderResource : broaderResources) {
                cls.addProperty(RDFS.subClassOf, broaderResource);
            }
            for (Resource narrowerResource : narrowerResources) {
                narrowerResource.addProperty(RDFS.subClassOf, cls);
            }
        }
    }

    ResIterator skosLabelIterator = model
            .listSubjectsWithProperty(model.getProperty("http://www.w3.org/2004/02/skos/core#prefLabel"));
    // Iterate over skos:broader properties to add the equivalent with the rdfs:subClassOf property
    /*while (skosLabelIterator.hasNext()) {
      List<Literal> labelResources = new ArrayList();
      Resource cls = skosLabelIterator.next();
      if (cls != null) {
        StmtIterator stmts = cls.listProperties();
        while (stmts.hasNext()) {
          // the iterator returns statements: [subject, predicate, object]
          StatementImpl tripleArray = (StatementImpl) stmts.next();
          if (tripleArray.getPredicate().toString().equals("http://www.w3.org/2004/02/skos/core#prefLabel")) {
    labelResources.add(tripleArray.getLiteral());
          }
        }
        // Add all label resource to rdfs:label
        for (Literal labelResource : labelResources) {
          cls.addProperty(RDFS.label, labelResource);
        }
      }
    }*/
    while (skosLabelIterator.hasNext()) {
        List<String> labelResources = new ArrayList();
        Resource cls = skosLabelIterator.next();
        if (cls != null) {
            StmtIterator stmts = cls.listProperties();
            while (stmts.hasNext()) {
                // the iterator returns statements: [subject, predicate, object]
                StatementImpl tripleArray = (StatementImpl) stmts.next();
                if (tripleArray.getPredicate().toString()
                        .equals("http://www.w3.org/2004/02/skos/core#prefLabel")) {
                    labelResources.add(tripleArray.getString());
                }
            }
            // Add all label resource to rdfs:label
            for (String labelResource : labelResources) {
                cls.addProperty(RDFS.label, labelResource);
            }
        }
    }

    String owlOntologyString = null;
    try {
        StringWriter out = new StringWriter();
        model.write(out, outputFormat);
        owlOntologyString = out.toString();
        if (outputFile != null) {
            model.write(new FileOutputStream(outputFile), outputFormat);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(YamFileHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
    return owlOntologyString;
}

From source file:com.datatorrent.stram.client.StramClientUtils.java

private static Configuration addDTSiteResources(Configuration conf, File confFile) {
    if (confFile.exists()) {
        LOG.info("Loading settings: " + confFile.toURI());
        conf.addResource(new Path(confFile.toURI()));
    } else {//from   ww  w  .ja v a2  s.c  o m
        LOG.info("Configuration file {} is not found. Skipping...", confFile.toURI());
    }
    return conf;
}

From source file:org.springsource.ide.eclipse.commons.core.SpringCoreUtils.java

public static URI getResourceURI(IResource resource) {
    if (resource != null) {
        URI uri = resource.getRawLocationURI();
        if (uri == null) {
            uri = resource.getLocationURI();
        }//w  w  w .j  a v a2s . co  m
        if (uri != null) {
            String scheme = uri.getScheme();
            if (FILE_SCHEME.equalsIgnoreCase(scheme)) {
                return uri;
            } else if (SOURCE_CONTROL_SCHEME.equals(scheme)) {
                // special case of Rational Team Concert
                IPath path = resource.getLocation();
                File file = path.toFile();
                if (file.exists()) {
                    return file.toURI();
                }
            } else {
                IPathVariableManager variableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
                return variableManager.resolveURI(uri);
            }
        }
    }
    return null;
}

From source file:com.threecrickets.sincerity.util.IoUtil.java

/**
 * Copies a complete subdirectory tree using Apache Commons VFS.
 * /*from w  w  w  .  ja  v a 2 s.c  o m*/
 * @param fromDir
 *        The source directory
 * @param toDir
 *        The target directory
 * @throws IOException
 *         In case of an I/O error
 */
public static void copyRecursive(File fromDir, File toDir) throws IOException {
    DefaultFileSystemManager manager = new DefaultFileSystemManager();
    try {
        DefaultLocalFileProvider fileProvider = new DefaultLocalFileProvider();
        manager.addProvider("file", fileProvider);
        manager.setDefaultProvider(fileProvider);
        manager.setFilesCache(new DefaultFilesCache());
        manager.init();
        copyRecursive(manager, manager.resolveFile(fromDir.toURI().toString()),
                manager.resolveFile(toDir.toURI().toString()));
    } finally {
        manager.close();
    }
}

From source file:net.ftb.util.DownloadUtils.java

public static String fileHash(File file, String type) throws IOException {
    if (!file.exists()) {
        return "";
    }/*from  ww w  .j  av a  2  s . c  o  m*/
    if (type.equalsIgnoreCase("md5"))
        return fileMD5(file);
    if (type.equalsIgnoreCase("sha1"))
        return fileSHA(file);
    URL fileUrl = file.toURI().toURL();
    MessageDigest dgest = null;
    try {
        dgest = MessageDigest.getInstance(type);
    } catch (NoSuchAlgorithmException e) {
    }
    InputStream str = fileUrl.openStream();
    byte[] buffer = new byte[65536];
    int readLen;
    while ((readLen = str.read(buffer, 0, buffer.length)) != -1) {
        dgest.update(buffer, 0, readLen);
    }
    str.close();
    Formatter fmt = new Formatter();
    for (byte b : dgest.digest()) {
        fmt.format("%02X", b);
    }
    String result = fmt.toString();
    fmt.close();
    return result;
}

From source file:hu.unideb.inf.rdfizers.rpm.ModelBuilder.java

/**
 * Processes the specified RPM package file.
 *
 * @param file the RPM package file//from   ww w  .  j av  a  2s. c  om
 * @throws IOException if an I/O error occurs
 * @return an RDF model that stores metadata obtained from the RPM package file
 */
public static Model process(File file) throws IOException {
    return process(new FileInputStream(file), file.toURI().toURL().toString());
}