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:org.apache.cxf.dosgi.systests.common.AbstractDosgiSystemTest.java

protected void installBundle(String groupId, String artifactId, String classifier, String type)
        throws Exception {
    String version = getBundleVersion(groupId, artifactId);
    File loc = localMavenBundle(groupId, artifactId, version, classifier, type);
    Bundle bundle = bundleContext.installBundle(loc.toURI().toString());
    bundle.start();//from w  w  w. ja v a2s .  c  o  m
}

From source file:com.hpl.mds.annotations.processors.JCompiler.java

private JCompiler() {
    try {/*from   w  ww.j a  v  a 2s  .c o  m*/
        Path outputPath = Paths.get(OUTPUT_DIR);
        File outputDirFile = outputPath.toFile();
        if (outputDirFile.exists()) {
            FileUtils.cleanDirectory(outputDirFile);
        }
        URL url = outputDirFile.toURI().toURL();
        CLASS_LOADER = new URLClassLoader(new URL[] { url });
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.pros.jsontransform.plugin.PluginManager.java

@SuppressWarnings("rawtypes")
private Class loadPlugin(final String pluginClassName) throws ObjectTransformerException {
    Class pluginClass = null;/*from w  w  w . ja  v  a 2  s  .  com*/

    try {
        if (urlClassLoader == null) {
            File folder = new File(pluginFolder);
            File[] listOfFiles = folder.listFiles();
            int jarCount = 0;
            URL[] jarUrls = new URL[listOfFiles.length];
            for (int i = 0; i < listOfFiles.length; i++) {
                File jarFile = listOfFiles[i];
                if (jarFile.isFile() && jarFile.getName().endsWith(".jar")) {
                    jarUrls[jarCount++] = jarFile.toURI().toURL();
                }
            }
            if (jarCount == 0) {
                throw new ObjectTransformerException("Cannot load plugin " + pluginClassName
                        + " No jars found in plugin folder " + pluginFolder);
            }
            urlClassLoader = new URLClassLoader(jarUrls);
        }
        pluginClass = urlClassLoader.loadClass(pluginClassName);
    } catch (Exception ex) {
        throw new ObjectTransformerException("Cannot load plugin " + pluginClassName, ex);
    }

    return pluginClass;
}

From source file:com.joyent.manta.client.crypto.SecretKeyUtilsTest.java

public void canLoadKeyFromURIPath() throws IOException {
    File file = File.createTempFile("ciphertext-", ".data");
    FileUtils.forceDeleteOnExit(file);/*  w  w w  . ja  va  2 s.c  o m*/
    FileUtils.writeByteArrayToFile(file, keyBytes);
    URI uri = file.toURI();

    SecretKey expected = SecretKeyUtils.loadKey(keyBytes, AesGcmCipherDetails.INSTANCE_128_BIT);
    SecretKey actual = SecretKeyUtils.loadKeyFromPath(Paths.get(uri), AesGcmCipherDetails.INSTANCE_128_BIT);

    Assert.assertEquals(actual.getAlgorithm(), expected.getAlgorithm());
    Assert.assertTrue(Arrays.equals(expected.getEncoded(), actual.getEncoded()),
            "Secret key loaded from URI doesn't match");
}

From source file:com.temenos.interaction.loader.detector.DirectoryChangeActionNotifier.java

protected void initWatchers(Collection<? extends File> resources) {
    if (scheduledTask != null) {
        scheduledTask.cancel(true);//w ww.j  a  v  a  2 s .  com
    }
    if (resources == null || resources.isEmpty() || getListeners() == null || getListeners().isEmpty()) {
        return;
    }
    try {
        WatchService ws = FileSystems.getDefault().newWatchService();
        for (File file : resources) {
            Path filePath = Paths.get(file.toURI());
            filePath.register(ws, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY,
                    StandardWatchEventKinds.ENTRY_DELETE);
        }

        watchService = ws;
        scheduledTask = executorService.scheduleWithFixedDelay(
                new ListenerNotificationTask(watchService, getListeners(), getIntervalSeconds() * 1000), 5,
                getIntervalSeconds(), TimeUnit.SECONDS);
    } catch (IOException ex) {
        throw new RuntimeException("Error configuring directory change listener - unexpected IOException", ex);
    }
}

From source file:io.fabric8.maven.enricher.standard.DependencyEnricher.java

private void addArtifactsWithYaml(EnricherContext buildContext, Set<URL> artifactSet, String dependencyYaml) {
    Set<Artifact> artifacts = isIncludeTransitive() ? buildContext.getProject().getArtifacts()
            : buildContext.getProject().getDependencyArtifacts();

    for (Artifact artifact : artifacts) {
        if (Artifact.SCOPE_COMPILE.equals(artifact.getScope()) && "jar".equals(artifact.getType())) {
            File file = artifact.getFile();
            try {
                URL url = new URL("jar:" + file.toURI().toURL() + "!/" + dependencyYaml);
                artifactSet.add(url);/*  w  w w  . ja v  a2  s. c  o  m*/
            } catch (MalformedURLException e) {
                getLog().debug("Failed to create URL for %s: %s", file, e);
            }
        }
    }
    // lets look on the current plugin classpath too
    if (isIncludePlugin()) {
        Enumeration<URL> resources = null;
        try {
            resources = getClass().getClassLoader().getResources(dependencyYaml);
        } catch (IOException e) {
            getLog().error("Could not find %s on the classpath: %s", dependencyYaml, e);
        }
        if (resources != null) {
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                artifactSet.add(url);
            }
        }
    }
}

From source file:com.haulmont.cuba.core.sys.remoting.RemotingServlet.java

@Override
public String getContextConfigLocation() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }/*from w w w  .jav a 2 s . c  o  m*/
    File baseDir = new File(AppContext.getProperty("cuba.confDir"));

    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] tokenArray = tokenizer.getTokenArray();
    StringBuilder locations = new StringBuilder();
    for (String token : tokenArray) {
        String location;
        if (ResourceUtils.isUrl(token)) {
            location = token;
        } else {
            if (token.startsWith("/"))
                token = token.substring(1);
            File file = new File(baseDir, token);
            if (file.exists()) {
                location = file.toURI().toString();
            } else {
                location = "classpath:" + token;
            }
        }
        locations.append(location).append(" ");
    }
    return locations.toString();
}

From source file:de.xirp.plugin.PluginManager.java

/**
 * Constructs a class loader for the given plugin information. The
 * loader has information about the jars of this plugin.
 * /*ww  w.j  a v  a 2 s .  c o m*/
 * @param info
 *            information about the plugin
 * @return a class loader which may be used for loading the plugin
 */
public static URLClassLoader getClassLoader(PluginInfo info) {
    File file = new File(info.getAbsoluteJarPath());

    List<URL> urls = getJarURLs(info);
    try {
        urls.add(file.toURI().toURL());
    } catch (MalformedURLException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    }

    URLClassLoader classLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]));
    return classLoader;
}

From source file:eu.scape_project.pc.droid.DroidIdentification.java

/**
 * Run droid identification on file//from w  ww.ja v  a 2s.  c  o m
 *
 * @param filePath Absolute file path
 * @return Result list
 * @throws FileNotFoundException
 * @throws IOException
 */
public String identify(String filePath) {
    InputStream in = null;
    String puid = "fmt/0";
    IdentificationRequest request = null;
    try {

        File file = new File(filePath);
        URI resourceUri = file.toURI();
        in = new FileInputStream(file);
        logger.debug("Identification of resource: " + resourceUri.toString());
        RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), file.getName());
        logger.debug("File length: " + file.length());
        logger.debug("File modified: " + file.lastModified());
        logger.debug("File name: " + file.getName());
        RequestIdentifier identifier = new RequestIdentifier(resourceUri);
        request = new FileSystemIdentificationRequest(metaData, identifier);
        request.open(in);
        IdentificationResultCollection results = bsi.matchBinarySignatures(request);
        bsi.removeLowerPriorityHits(results);
        if (results == null || results.getResults() == null || results.getResults().isEmpty()) {
            logger.warn("No identification result");
        } else {
            List<IdentificationResult> result = results.getResults();
            if (result != null && !result.isEmpty()) {
                for (IdentificationResult ir : result) {
                    String id = ir.getPuid();
                    if (id != null && !id.isEmpty()) {
                        // take first puid, ignore others
                        puid = id;
                        break;
                    }
                }
            }
            if (puid.isEmpty()) {
                puid = "fmt/0"; // unknown
            }
        }
        request.close();
    } catch (IOException ex) {
        logger.error("I/O Exception", ex);
    } finally {
        try {
            if (request != null) {
                request.close();
            }
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            logger.warn("I/O error when closing stream", ex);
        }
    }

    return puid;
}

From source file:io.fabric8.apiman.Fabric8ManagerApiMicroService.java

protected void startSsl() throws Exception {
    long startTime = System.currentTimeMillis();

    //Secret should be mounted at /secret
    File passwordFile = new File(ApimanStarter.KEYSTORE_PASSWORD_PATH);
    String password = IOUtils.toString(passwordFile.toURI());
    if (password != null)
        password = password.trim();//from www.  j  a  va 2s .  c om

    HttpConfiguration https = new HttpConfiguration();
    https.addCustomizer(new SecureRequestCustomizer());

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(ApimanStarter.KEYSTORE_PATH);
    sslContextFactory.setKeyStorePassword(password);
    sslContextFactory.setKeyManagerPassword(password);

    // Create the server.
    int serverPort = serverPort();
    log.info("**** Starting SslServer (" + getClass().getSimpleName() + ") on port: " + serverPort);
    sslServer = new Server();

    ServerConnector sslConnector = new ServerConnector(sslServer,
            new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
    sslConnector.setPort(serverPort);
    sslServer.setConnectors(new Connector[] { sslConnector });

    HandlerCollection handlers = new HandlerCollection();
    addModulesToJetty(handlers);

    sslServer.setHandler(handlers);
    sslServer.start();
    long endTime = System.currentTimeMillis();
    log.info("******* Started in " + (endTime - startTime) + "ms");
}