Example usage for java.nio.file Path toUri

List of usage examples for java.nio.file Path toUri

Introduction

In this page you can find the example usage for java.nio.file Path toUri.

Prototype

URI toUri();

Source Link

Document

Returns a URI to represent this path.

Usage

From source file:org.bimserver.plugins.classloaders.FileJarClassLoader.java

public FileJarClassLoader(PluginManager pluginManager, ClassLoader parentClassLoader, Path jarFile)
        throws FileNotFoundException, IOException {
    super(parentClassLoader);
    this.jarFile = jarFile;
    URI uri = jarFile.toUri();
    try {/*from   w  ww  . j  a  v  a2  s  .c  o  m*/
        URI x = new URI("jar:" + uri.toString());
        fileSystem = pluginManager.getOrCreateFileSystem(x);
    } catch (URISyntaxException e) {
        LOGGER.error("", e);
    }
}

From source file:org.apache.hadoop.security.ssl.HopsSSLTestUtils.java

protected void setCryptoConfig(Configuration conf, String classPathDir) throws Exception {
    conf.set(CommonConfigurationKeysPublic.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY,
            "org.apache.hadoop.net.HopsSSLSocketFactory");
    conf.setBoolean(CommonConfigurationKeysPublic.IPC_SERVER_SSL_ENABLED, true);
    conf.set(SSLFactory.SSL_ENABLED_PROTOCOLS, "TLSv1.2,TLSv1.1");
    conf.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "ALLOW_ALL");
    String user = UserGroupInformation.getCurrentUser().getUserName();
    conf.set(ProxyUsers.CONF_HADOOP_PROXYUSER + "." + user, "*");

    Configuration sslServerConf = KeyStoreTestUtil.createServerSSLConfig(serverKeyStore.toString(), passwd,
            passwd, serverTrustStore.toString(), passwd, "");
    Path sslServerPath = Paths.get(classPathDir, HopsSSLTestUtils.class.getSimpleName() + ".ssl-server.xml");
    filesToPurge.add(sslServerPath);//from   w ww .  ja va  2  s .c o m
    File sslServer = new File(sslServerPath.toUri());
    KeyStoreTestUtil.saveConfig(sslServer, sslServerConf);
    conf.set(SSLFactory.SSL_SERVER_CONF_KEY, HopsSSLTestUtils.class.getSimpleName() + ".ssl-server.xml");

    // Set the client certificate with correct CN and signed by the CA
    conf.set(HopsSSLSocketFactory.CryptoKeys.KEY_STORE_FILEPATH_KEY.getValue(), c_clientKeyStore.toString());
    conf.set(HopsSSLSocketFactory.CryptoKeys.KEY_STORE_PASSWORD_KEY.getValue(), passwd);
    conf.set(HopsSSLSocketFactory.CryptoKeys.KEY_PASSWORD_KEY.getValue(), passwd);
    conf.set(HopsSSLSocketFactory.CryptoKeys.TRUST_STORE_FILEPATH_KEY.getValue(),
            c_clientTrustStore.toString());
    conf.set(HopsSSLSocketFactory.CryptoKeys.TRUST_STORE_PASSWORD_KEY.getValue(), passwd);
    conf.set(HopsSSLSocketFactory.CryptoKeys.SOCKET_ENABLED_PROTOCOL.getValue(), "TLSv1.2");
}

From source file:cz.muni.fi.mir.services.MathCanonicalizerLoaderImpl.java

@Override
public void execute(List<Formula> formulas, ApplicationRun applicationRun) throws IllegalStateException {
    if (!fileService.canonicalizerExists(applicationRun.getRevision().getRevisionHash())) {
        throw new IllegalStateException("Given canonicalizer with revision ["
                + applicationRun.getRevision().getRevisionHash() + "] does not exists.");
    } else {/* www  .j  ava2s  . c om*/
        Path path = FileSystems.getDefault().getPath(this.jarFolder,
                applicationRun.getRevision().getRevisionHash() + ".jar");
        Class mainClass = null;
        URL jarFile = null;
        try {
            jarFile = path.toUri().toURL();
        } catch (MalformedURLException me) {
            logger.fatal(me);
        }
        URLClassLoader cl = URLClassLoader.newInstance(new URL[] { jarFile });

        try {
            mainClass = cl.loadClass("cz.muni.fi.mir.mathmlcanonicalization." + this.mainClassName);
        } catch (ClassNotFoundException cnfe) {
            logger.fatal(cnfe);
        }

        CanonicalizationTask ct = taskFactory.createTask();

        ct.setDependencies(formulas, applicationRun, mainClass);

        taskService.submitTask(ct);
    }
}

From source file:org.apache.hadoop.hbase.tool.coprocessor.CoprocessorValidator.java

private List<URL> buildClasspath(List<String> jars) throws IOException {
    List<URL> urls = new ArrayList<>();

    for (String jar : jars) {
        Path jarPath = Paths.get(jar);
        if (Files.isDirectory(jarPath)) {
            try (Stream<Path> stream = Files.list(jarPath)) {
                List<Path> files = stream.filter((path) -> Files.isRegularFile(path))
                        .collect(Collectors.toList());

                for (Path file : files) {
                    URL url = file.toUri().toURL();
                    urls.add(url);//from w  ww . j a  va2s.  co  m
                }
            }
        } else {
            URL url = jarPath.toUri().toURL();
            urls.add(url);
        }
    }

    return urls;
}

From source file:org.wrml.mojo.schema.builder.SchemaBuilderMojo.java

public void execute() throws MojoExecutionException {
    /*//from   www. j a  v a 2s .c om
     * Recursive decent into the _ResourcesDirectory looking for files with
    * the extension .mdl These are JSON files that describe a model. Read
    * each .mdl file and generate a class in the target directory that
    * implements the model.
    */
    File mainDir = _ResourcesDirectory.getParentFile();
    if (!mainDir.isDirectory()) {
        throw new MojoExecutionException(
                String.format("%s is not a directory.", _ResourcesDirectory.getPath()));
    }

    File rootWrmlModelDir = new File(mainDir, "wrml-model");
    File rootJsonSchemaDir = new File(mainDir, "json-schema");

    getLog().info("Expected JsonSchema Location: " + rootJsonSchemaDir.toString());
    getLog().info("Expected Wrml Model location: " + rootWrmlModelDir.toString());
    Path rootWrmlModelPath = rootWrmlModelDir.toPath();
    Path rootJsonSchemaPath = rootJsonSchemaDir.toPath();

    _RootWrmlModelUri = rootWrmlModelPath.toUri();
    _RootJsonSchemaUri = rootJsonSchemaPath.toUri();

    try {
        _Engine = createEngine();
    } catch (IOException e) {
        throw new MojoExecutionException("Error creating wrml engine.", e);
    }

    try {
        if (rootJsonSchemaDir.isDirectory()) {
            getLog().info("Processing: " + rootJsonSchemaDir.toString());
            File manifest = new File(rootJsonSchemaDir + File.separator + MANIFEST_NAME);
            if (manifest.exists() && manifest.isFile()) {
                getLog().info("Using file Manifest...");
                decendManifest(manifest);
            } else {
                getLog().info(
                        "No Manifest at " + manifest.getAbsolutePath() + ", decending per directories...");
                decend(rootJsonSchemaDir, SourceType.JSON_SCHEMA);
            }
        }
        if (rootWrmlModelDir.isDirectory()) {
            getLog().info("Processing: " + rootWrmlModelDir.toString());
            decend(rootWrmlModelDir, SourceType.WRML_MODEL);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error generating models.", e);
    }
}

From source file:org.lenskit.data.dao.file.TextEntitySource.java

/**
 * Set the source file for this reader./*from  ww  w .  j a va 2 s  .c o  m*/
 * @param file The source file.
 */
public void setFile(Path file) {
    source = Files.asCharSource(file.toFile(), Charset.defaultCharset());
    try {
        sourceURL = file.toUri().toURL();
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("invalid URL " + file, e);
    }
}

From source file:org.objectpocket.storage.blob.MultiZipBlobStore.java

private synchronized FileSystem getReadFileSystem(String name) throws IOException {
    FileSystem fileSystem = readFileSystems.get(name);
    if (fileSystem == null || !fileSystem.isOpen()) {
        Path path = Paths.get(directory + "/" + name);
        URI uri = URI.create("jar:" + path.toUri());
        Map<String, String> env = new HashMap<>();
        fileSystem = FileSystems.newFileSystem(uri, env);
        readFileSystems.put(name, fileSystem);
    }//w  ww . j a va 2 s. c om
    return fileSystem;
}

From source file:org.sonarlint.intellij.core.SonarLintServerManager.java

private URL[] loadPlugins() throws IOException, URISyntaxException {
    URL pluginsDir = this.getClass().getClassLoader().getResource("plugins");

    if (pluginsDir == null) {
        throw new IllegalStateException("Couldn't find plugins");
    }/*  ww  w  . j a  v a2  s. c  o m*/

    List<URL> pluginsUrls = new ArrayList<>();
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(pluginsDir.toURI()),
            "*.jar")) {
        for (Path path : directoryStream) {
            globalLogOutput.log("Found plugin: " + path.getFileName().toString(), LogOutput.Level.DEBUG);
            pluginsUrls.add(path.toUri().toURL());
        }
    }
    return pluginsUrls.toArray(new URL[pluginsUrls.size()]);
}

From source file:org.objectpocket.storage.blob.MultiZipBlobStore.java

private synchronized FileSystem getWriteFileSystem(String name) throws IOException {
    FileSystem fileSystem = writeFileSystems.get(name);
    if (fileSystem == null || !fileSystem.isOpen()) {
        closeReadFileSystem(name);//from   w  w w  .  j a  va  2 s.co  m
        Path path = Paths.get(new File(directory + "/" + name).getAbsolutePath());
        URI uri = URI.create("jar:" + path.toUri());
        Map<String, String> env = new HashMap<>();
        env.put("create", "true");
        fileSystem = FileSystems.newFileSystem(uri, env);
        writeFileSystems.put(name, fileSystem);
    }
    return fileSystem;
}

From source file:net.sourceforge.pmd.cache.AbstractAnalysisCache.java

private URL[] getClassPathEntries() {
    final String classpath = System.getProperty("java.class.path");
    final String[] classpathEntries = classpath.split(File.pathSeparator);
    final List<URL> entries = new ArrayList<>();

    final SimpleFileVisitor<Path> fileVisitor = new SimpleFileVisitor<Path>() {
        @Override/*w w w.j  a v  a  2  s  .  co m*/
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            if (!attrs.isSymbolicLink()) { // Broken link that can't be followed
                entries.add(file.toUri().toURL());
            }
            return FileVisitResult.CONTINUE;
        }
    };
    final SimpleFileVisitor<Path> jarFileVisitor = new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            String extension = FilenameUtils.getExtension(file.toString());
            if ("jar".equalsIgnoreCase(extension)) {
                fileVisitor.visitFile(file, attrs);
            }
            return FileVisitResult.CONTINUE;
        }
    };

    try {
        for (final String entry : classpathEntries) {
            final File f = new File(entry);
            if (isClassPathWildcard(entry)) {
                Files.walkFileTree(new File(entry.substring(0, entry.length() - 1)).toPath(),
                        EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, jarFileVisitor);
            } else if (f.isFile()) {
                entries.add(f.toURI().toURL());
            } else {
                Files.walkFileTree(f.toPath(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                        fileVisitor);
            }
        }
    } catch (final IOException e) {
        LOG.log(Level.SEVERE, "Incremental analysis can't check execution classpath contents", e);
        throw new RuntimeException(e);
    }

    return entries.toArray(new URL[0]);
}