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:info.mikaelsvensson.devtools.sitesearch.PathUtilsTest.java

public void testTwoPaths(final String[] sourcePath, final String[] targetPath) {

    Collection<String> errors = new LinkedList<String>();

    for (int i = 10; i < targetPath.length; i++) {
        String target = StringUtils.join(targetPath, '\\', 0, i + 1);
        for (int j = 10; j < sourcePath.length; j++) {
            String source = StringUtils.join(sourcePath, '\\', 0, j + 1);
            System.out.println(source);
            System.out.println(target);
            File sourceFile = new File(source);
            String relativePath = PathUtils.getRelativePath(sourceFile, new File(target));

            System.out.println(relativePath);
            File sourceFolder = sourceFile.isDirectory() ? sourceFile : sourceFile.getParentFile();

            File actual = new File(sourceFolder, relativePath.replace(PathUtils.SEP, File.separatorChar));
            File expected = new File(target);
            boolean isEqual = actual.toURI().normalize().equals(expected.toURI().normalize());
            if (!isEqual) {
                errors.add("The path from " + source + " to " + target + " is NOT " + actual);
            }//  w ww  .j  a va  2s .c  o  m
        }
    }

    assertTrue(errors.toString(), errors.size() == 0);
}

From source file:org.pentaho.pat.server.util.JdbcDriverFinder.java

private void scan(final long timeMil) {

    final FilenameFilter libs = new FilenameFilter() {

        public boolean accept(final File dir, final String pathname) {
            return pathname.endsWith("jar") || pathname.endsWith("zip"); //$NON-NLS-1$//$NON-NLS-2$
        }/*from w w  w . ja va  2  s . c  o m*/

    };

    final ResolverUtil<Driver> resolver = new ResolverUtil<Driver>();

    for (File directory : this.jdbcDriverDirectory) {
        for (File lib : directory.listFiles(libs)) {
            try {
                resolver.loadImplementationsInJar("", lib.toURI().toURL(), //$NON-NLS-1$
                        new ResolverUtil.IsA(Driver.class));
            } catch (MalformedURLException e) {
                LOG.trace(e);
                continue;
            }
        }
    }
    List<String> drivers = new ArrayList<String>();
    for (Class<? extends Driver> cd : resolver.getClasses()) {
        drivers.add(cd.getName());
    }
    this.lastCall = timeMil;
    this.drivers = drivers;
}

From source file:com.twitter.distributedlog.feature.DynamicConfigurationFeatureProvider.java

@Override
public void start() throws IOException {
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayListWithExpectedSize(2);
    String baseConfigPath = conf.getFileFeatureProviderBaseConfigPath();
    Preconditions.checkNotNull(baseConfigPath);
    File baseConfigFile = new File(baseConfigPath);
    FileConfigurationBuilder baseProperties = new PropertiesConfigurationBuilder(
            baseConfigFile.toURI().toURL());
    fileConfigBuilders.add(baseProperties);
    String overlayConfigPath = conf.getFileFeatureProviderOverlayConfigPath();
    if (null != overlayConfigPath) {
        File overlayConfigFile = new File(overlayConfigPath);
        FileConfigurationBuilder overlayProperties = new PropertiesConfigurationBuilder(
                overlayConfigFile.toURI().toURL());
        fileConfigBuilders.add(overlayProperties);
    }/*from   w ww  . ja v a2 s .c o m*/
    try {
        this.featuresConfSubscription = new ConfigurationSubscription(this.featuresConf, fileConfigBuilders,
                executorService, conf.getDynamicConfigReloadIntervalSec(), TimeUnit.SECONDS);
    } catch (ConfigurationException e) {
        throw new IOException("Failed to register subscription on features configuration");
    }
    this.featuresConfSubscription.registerListener(this);
}

From source file:com.facebook.hiveio.mapreduce.output.WritingTool.java

/**
 * set hive configuration/*from  ww w  .j av  a2 s.  co  m*/
 *
 * @param conf Configuration
 */
private void adjustConfigurationForHive(Configuration conf) {
    // when output partitions are used, workers register them to the
    // metastore at cleanup stage, and on HiveConf's initialization, it
    // looks for hive-site.xml.
    addToStringCollection(conf, "tmpfiles", conf.getClassLoader().getResource("hive-site.xml").toString());

    // Or, more effectively, we can provide all the jars client needed to
    // the workers as well
    String[] hadoopJars = System.getenv("HADOOP_CLASSPATH").split(File.pathSeparator);
    List<String> hadoopJarURLs = Lists.newArrayList();
    for (String jarPath : hadoopJars) {
        File file = new File(jarPath);
        if (file.exists() && file.isFile()) {
            String jarURL = file.toURI().toString();
            hadoopJarURLs.add(jarURL);
        }
    }
    addToStringCollection(conf, "tmpjars", hadoopJarURLs);
}

From source file:com.enonic.cms.core.plugin.container.OsgiContainer.java

private Map<String, String> createConfigMap() throws Exception {
    final Map<String, String> map = Maps.newHashMap();

    map.put(FRAMEWORK_STORAGE, this.tmpDir.getAbsolutePath());
    map.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    map.put(HookRegistry.PROP_HOOK_CONFIGURATORS,
            BaseHookConfigurator.class.getName() + "," + DynamicHookConfigurator.class.getName());
    map.put(HookRegistry.PROP_HOOK_CONFIGURATORS_EXCLUDE, EclipseLogHook.class.getName());

    final File installArea = new File(this.tmpDir, "__install");
    installArea.mkdirs();//from ww w.  j  a v a2  s .  c  o  m

    map.put("osgi.install.area", installArea.toURI().toString());

    final File frameworkJar = new File(installArea, "framework.jar");
    map.put("osgi.framework", frameworkJar.toURI().toString());

    copyFrameworkJar(frameworkJar);
    return map;
}

From source file:com.mkl.websuites.internal.tests.ScenarioFolderTest.java

private void processRecursivelyFolder(Path folderPath, TestSuite parentSuite) {

    TestSuite currentFolderSuite;//  w  ww .j  av  a2 s.co m
    if (isTopTest) {
        currentFolderSuite = new TestSuite(folderPath.toString());
        isTopTest = false;
    } else {
        currentFolderSuite = new TestSuite(
                folderPath.subpath(folderPath.getNameCount() - 1, folderPath.getNameCount()).toString());
    }

    List<Test> testsInCurrentFolder = processScenarioFilesInFolder(folderPath.toString());

    for (Test test : testsInCurrentFolder) {
        currentFolderSuite.addTest(test);
    }

    parentSuite.addTest(currentFolderSuite);

    if (ignoreSubfolders) {
        return;
    }

    File folder = new File(folderPath.toString());

    File[] nestedFolders = folder.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.isDirectory();
        }
    });

    if (nestedFolders == null) {
        throw new WebServiceException(String.format("Error while traversing through folder "
                + "structure starting from path '%s'. Probably there is something wrong "
                + "in the path string.", folderPath));
    }

    sort(nestedFolders);

    for (File nested : nestedFolders) {

        processRecursivelyFolder(Paths.get(nested.toURI()), currentFolderSuite);
    }

}

From source file:de.kaiserpfalzEdv.office.core.license.impl.LicenseServiceImpl.java

private void loadLicenseFile() throws CantLoadLicenseException, LicenseCheckFailedException {
    File f = new File(licenseFile);

    if (f.exists()) {
        LOG.info("Loading license: {}", f.toURI());
    } else {//from  w  ww. j a  va 2s.c  o m
        LOG.warn("License file does not exist: {}", f.toURI());
    }

    try {
        rawLicense.setLicenseEncodedFromFile(f.getCanonicalPath());
    } catch (IOException | PGPException e) {
        throw new CantLoadLicenseException(f.getAbsolutePath(), e);
    }
}

From source file:com.temenos.interaction.loader.classloader.CachingParentLastURLClassloaderFactory.java

protected synchronized URLClassLoader createClassLoader(Object currentState, FileEvent<File> param) {
    try {/*from   w  ww.j  a  v  a  2 s .  co m*/
        LOGGER.debug(
                "Classloader requested from CachingParentLastURLClassloaderFactory, based on FileEvent reflecting change in {}",
                param.getResource().getAbsolutePath());
        Set<URL> urls = new HashSet<URL>();
        File newTempDir = new File(FileUtils.getTempDirectory(), currentState.toString());
        FileUtils.forceMkdir(newTempDir);
        Collection<File> files = FileUtils.listFiles(param.getResource(), new String[] { "jar" }, true);
        for (File f : files) {
            try {
                LOGGER.trace("Adding {} to list of URLs to create classloader from", f.toURI().toURL());
                FileUtils.copyFileToDirectory(f, newTempDir);
                urls.add(new File(newTempDir, f.getName()).toURI().toURL());
            } catch (MalformedURLException ex) {
                // should not happen, we do have the file there
                // but if, what can we do - just log it
                LOGGER.warn("Trying to intilialize classloader based on URL failed!", ex);
            }
        }
        lastClassloaderTempDir = newTempDir;
        URLClassLoader classloader = new ParentLastURLClassloader(urls.toArray(new URL[] {}),
                Thread.currentThread().getContextClassLoader());

        return classloader;
    } catch (IOException ex) {
        throw new RuntimeException("Unexpected error trying to create new classloader.", ex);
    }
}

From source file:se.crisp.codekvast.agent.daemon.appversion.ManifestAppVersionStrategy.java

private File getJarFile(File codeBaseFile, String jarUri) throws IOException, URISyntaxException {
    URL url = null;/* w w  w  .j  ava2s.c o  m*/
    // try to parse it as a URL...
    try {
        url = new URL(jarUri);
    } catch (MalformedURLException ignore) {
    }

    if (url == null) {
        // Try to treat it as a file...
        File file = new File(jarUri);
        if (file.isFile() && file.canRead() && file.getName().endsWith(".jar")) {
            url = file.toURI().toURL();
        }
    }
    if (url == null) {
        // Search for it in codeBaseFile. Treat it as a regular expression for the basename
        url = search(codeBaseFile, jarUri);
    }

    File result = url == null ? null : new File(url.toURI());
    if (result == null || !result.canRead()) {
        throw new IOException("Cannot read " + jarUri);
    }
    return result;
}

From source file:com.bazaarvoice.seo.sdk.url.BVSeoSdkURLBuilder.java

private URI fileUri(String path) {
    String fileRoot = bvConfiguration.getProperty(BVClientConfig.LOCAL_SEO_FILE_ROOT.getPropertyName());
    if (StringUtils.isBlank(fileRoot)) {
        throw new BVSdkException("ERR0010");
    }//from   w w  w .  j  a  v  a2  s .c  o  m

    String fullFilePath = fileRoot + "/" + path;
    File file = new File(fullFilePath);
    return file.toURI();
}