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.efs.openreports.dispatcher.XMLADispatcher.java

protected String makeDataSourcesUrl(ServletConfig servletConfig) {
    String paramValue = servletConfig.getInitParameter(PARAM_DATASOURCES_CONFIG);
    // if false, then do not throw exception if the file/url
    // can not be found
    boolean optional = getBooleanInitParameter(servletConfig, PARAM_OPTIONAL_DATASOURCE_CONFIG);

    URL dataSourcesConfigUrl = null;
    try {/* w w  w .j a v a2  s. c o  m*/
        if (paramValue == null) {
            // fallback to default
            String defaultDS = directoryProvider.getReportDirectory() + DEFAULT_DATASOURCE_FILE;
            File realPath = new File(defaultDS);
            if (realPath.exists()) {
                // only if it exists
                dataSourcesConfigUrl = realPath.toURI().toURL();
                return dataSourcesConfigUrl.toString();
            } else {
                return null;
            }
        } else if (paramValue.startsWith("inline:")) {
            return paramValue;
        } else {
            paramValue = Util.replaceProperties(paramValue, Util.toMap(System.getProperties()));
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("XmlaServlet.makeDataSources: paramValue=" + paramValue);
            }
            // is the parameter a valid URL
            MalformedURLException mue = null;
            try {
                dataSourcesConfigUrl = new URL(paramValue);
            } catch (MalformedURLException e) {
                // not a valid url
                mue = e;
            }
            if (dataSourcesConfigUrl == null) {
                // see if its a full valid file path
                File f = new File(paramValue);
                if (f.exists()) {
                    // yes, a real file path
                    dataSourcesConfigUrl = f.toURI().toURL();
                } else if (mue != null) {
                    // neither url or file,
                    // is it not optional
                    if (!optional) {
                        throw mue;
                    }
                }
                return null;
            }
            return dataSourcesConfigUrl.toString();
        }
    } catch (MalformedURLException mue) {
        throw Util.newError(mue, "invalid URL path '" + paramValue + "'");
    }
}

From source file:azkaban.flowtrigger.plugin.FlowTriggerDependencyPluginManager.java

private DependencyCheck createDependencyCheck(final DependencyPluginConfig pluginConfig)
        throws FlowTriggerDependencyPluginException {
    final String classPath = pluginConfig.get(CLASS_PATH);

    final String[] cpList = classPath.split(",");

    final List<URL> resources = new ArrayList<>();

    try {/*from   w  w w  .  j  a va  2  s .c om*/
        for (final String cp : cpList) {
            final File[] files = getFilesMatchingPath(cp);
            if (files != null) {
                for (final File file : files) {
                    final URL cpItem = file.toURI().toURL();
                    if (!resources.contains(cpItem)) {
                        logger.info("adding to classpath " + cpItem);
                        resources.add(cpItem);
                    }
                }
            }
        }
    } catch (final Exception ex) {
        throw new FlowTriggerDependencyPluginException(ex);
    }

    final ClassLoader dependencyClassloader = new ParentLastURLClassLoader(
            resources.toArray(new URL[resources.size()]), this.getClass().getClassLoader());

    Thread.currentThread().setContextClassLoader(dependencyClassloader);

    Class<? extends DependencyCheck> clazz = null;
    try {
        clazz = (Class<? extends DependencyCheck>) dependencyClassloader
                .loadClass(pluginConfig.get(DEPENDENCY_CLASS));
        return (DependencyCheck) Utils.callConstructor(clazz);
    } catch (final Exception ex) {
        throw new FlowTriggerDependencyPluginException(ex);
    }
}

From source file:de.cologneintelligence.fitgoodies.maven.FitIntegrationTestMojo.java

private URL[] createClasspath() throws MojoExecutionException {
    List<String> classpathElements = getClasspath();
    classpathElements.add(project.getBuild().getOutputDirectory());
    classpathElements.add(project.getBuild().getTestOutputDirectory());

    URL[] urls = new URL[classpathElements.size()];
    for (int i = 0; i < classpathElements.size(); i++) {
        File file = new File(classpathElements.get(i));
        try {/*www.j  av a2s .c  o  m*/
            urls[i] = file.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new MojoExecutionException("Could not build classpath with '" + file + "'", e);
        }
    }

    return urls;
}

From source file:gov.va.vinci.leo.descriptors.LeoAEDescriptorTest.java

@Test
public void testToXmlWithName() throws Exception {
    LeoAEDescriptor fd = new LeoAEDescriptor("desc.gov.va.vinci.leo.ae.TokenizerAggregateDescriptor", true);
    String name = fd.getName();// w  ww .j  av a  2s.c  o m
    File xmlPath = new File(rootDirectory + "src/test/resources/xml-generated-test");
    xmlPath.mkdir();
    fd.setDescriptorLocator(xmlPath.toURI());
    fd.toXML(name);
    assertTrue(xmlPath.listFiles().length == 3);
    FileUtils.forceDelete(xmlPath);
}

From source file:de.cologneintelligence.fitgoodies.maven.FitIntegrationTestMojo.java

private String createClassPathString(URL[] classpath) {
    StringBuilder classPathBuilder = new StringBuilder();

    for (URL url : classpath) {
        appendToClasspath(url, classPathBuilder);
    }//from w w  w .j  a v a 2  s .  co  m

    for (File element : additionalClasspathElements) {
        try {
            appendToClasspath(element.toURI().toURL(), classPathBuilder);
        } catch (MalformedURLException e) {
            throw new RuntimeException("Cannot convert file to url: " + element, e);
        }
    }

    return classPathBuilder.toString();
}

From source file:com.google.dart.tools.ui.theme.preferences.TemporaryProject.java

private IProjectDescription createProjectDescription(IProject project) {
    URI location = null;/* w  ww  .j  av  a2 s  .c o  m*/
    try {
        File tempFile = File.createTempFile("DartEditor", null);
        File tempDir = tempFile.getParentFile();
        tempFile.delete();
        tempDir.mkdirs();
        location = tempDir.toURI();
    } catch (IOException ex) {
        Activator.logError(ex);
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProjectDescription description = workspace.newProjectDescription(project.getName());
    description.setLocationURI(location);
    description.setNatureIds(new String[] { DartCore.DART_PROJECT_NATURE });
    ICommand command = description.newCommand();
    command.setBuilderName(DartCore.DART_BUILDER_ID);
    description.setBuildSpec(new ICommand[] { command });
    return description;
}

From source file:architecture.ee.jdbc.sqlquery.factory.impl.AbstractSqlQueryFactory.java

public long getDeploymentTime(File file) {
    if (isFileDeployed(file))
        return deployments.get(file.toURI()).deployedTime;
    return 0;/*from   w  w w  . j a  v  a  2  s  .  co  m*/
}

From source file:com.msopentech.thali.utilities.android.AndroidXmlHttpRequestTestActivity.java

@Override
public void LoadWebPage(final String url) {
    readResourceIntoDirectory(BridgeManager.pathToBridgeManagerJs);

    try {//  w  w  w  . j a  v  a  2  s . c o m
        loadManifestFilesIntoDirectory("/xhrtest/");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    final File testHtmlFile = new File(getFilesDir(), "/xhrtest/test.html");
    this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            webView.loadUrl(testHtmlFile.toURI().toString());
        }
    });
}

From source file:org.jtalks.poulpe.web.listener.LoggerInitializationListener.java

/**
 * Configures log4j from external file//from   w  ww  .  j  a v  a  2  s.c  o m
 *
 * @param fileInfo file description and path
 */
private boolean loadLog4jConfigurationFromExternalFile(FileInfo fileInfo) {
    if (fileInfo == null) {
        return false;
    }
    logToConsole("Log4j configuration file has been taken from " + fileInfo.getSource() + " and set to ["
            + fileInfo.getLogConfigPath() + "]");
    String log4jConfigurationFile = fileInfo.getLogConfigPath();
    File file = new File(log4jConfigurationFile.trim());
    URL url;
    try {
        url = file.toURI().toURL();
    } catch (MalformedURLException e) {
        return false;
    }
    return configureLog4j(url);
}

From source file:com.adaptris.util.URLString.java

/**
 * Construct a URLString from a java.io.File object.
 * /*from w w  w .j  a  va 2  s.  c om*/
 * @throws MalformedURLException
 */
public URLString(File file) throws MalformedURLException {
    this(file.toURI().toURL());
}