List of usage examples for java.io File toURI
public URI toURI()
From source file:com.thoughtworks.go.util.FileUtil.java
public static String toFileURI(File file) { URI uri = file.toURI(); String uriString = uri.toASCIIString(); return uriString.replaceAll("^file:/", "file:///"); }
From source file:Main.java
/** * Writes the contents from the given input stream to the given file. * * @param in the InputStream to read from * @param outputFileName the name of the file to write to * @return the URL for the local file/*from w ww. j a va 2s. com*/ */ public static String writeStreamToFile(InputStream in, String outputFileName) throws IOException { File file = new File(outputFileName); // Create the parent directory. file.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(file); try { copy(in, out); // Return the URL to the output file. return file.toURI().toString(); } finally { out.flush(); out.close(); } }
From source file:uk.dsxt.voting.common.utils.PropertiesHelper.java
public static URL getConfOrResourceFile(String fileName) { File confFile = getConfFile(fileName); log.debug("Configuration path: {}", confFile.getAbsolutePath()); if (confFile.exists()) { try {/*from www . j a va2 s .c o m*/ return confFile.toURI().toURL(); } catch (MalformedURLException e) { log.error("Couldn't get URL from file: {}. error={}", confFile, e.getMessage()); } } return getResource(fileName); }
From source file:coolmap.application.plugin.PluginMaster.java
public static void initialize() { String pluginPath;/*from ww w. java2 s . com*/ if (Config.isInitialized()) { pluginPath = Config.getProperty(Config.PLUGIN_DIRECTORY); } else { pluginPath = "plugin"; } File pluginFolder = new File(pluginPath); // System.out.println(pluginFolder.getAbsolutePath()); pluginManager = PluginManagerFactory.createPluginManager(); pluginManager.addPluginsFrom(pluginFolder.toURI()); // after loading everything pluginManagerUtil = new PluginManagerUtil(pluginManager); Collection<CoolMapPlugin> plugins = pluginManagerUtil.getPlugins(CoolMapPlugin.class); Collection<PluginInformation> pluginInfo = pluginManagerUtil.getPlugins(PluginInformation.class); PluginInformationImpl piImpl = null; if (!pluginInfo.isEmpty()) { piImpl = (PluginInformationImpl) pluginInfo.iterator().next(); } for (CoolMapPlugin plugin : plugins) { try { CMConsole.logInfo("Loaded " + plugin.getName() + " plugin"); // System.out.println(plugin.getName()); JSONObject config = new JSONObject(); if (piImpl != null) { //gets the string try { Collection<String> paths = piImpl .getInformation(PluginInformation.Information.CLASSPATH_ORIGIN, plugin); if (!paths.isEmpty()) { config.put(CoolMapPluginTerms.ATTR_URI, paths.iterator().next()); } } catch (Exception e) { //do nothing, not found } } plugin.initialize(config); } catch (Exception e) { CMConsole.logWarning("Loaded '" + plugin.getName() + "' plugin"); CMConsole.logToFile(e); } } }
From source file:webfx.URLVerifier.java
public static URL verifyURL(String location) throws MalformedURLException { URL url;/*from w ww . j a v a 2s.c o m*/ try { url = new URL(location); } catch (MalformedURLException e) { File f = new File(location.trim()); if (f.isAbsolute() && f.exists()) { url = f.toURI().toURL(); } else { url = new URL("http://" + location); } } return url; }
From source file:com.tera.common.vcontext.service.ContextConfigurationParser.java
/** * @param bundle com.tera.common.vcontext bundle * @param directory top directory with filesystem data *//*from w ww. ja v a 2 s . c o m*/ public static final void parseConfigurationDirectory(Bundle bundle, String directory) { Unmarshaller un = JaxbUtil.create(VContextTemplate.class, bundle.getResource("vcontext.xsd")); File file = new File(directory); if (file.isDirectory()) { File[] contextDirs = file.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); log.info("Found {} filesystem directories", contextDirs.length); for (File dir : contextDirs) { Collection<File> contextFiles = FileUtils.listFiles(dir, new NameFileFilter("vcontext.xml"), null); for (File contextFile : contextFiles) { try { VContextTemplate context = (VContextTemplate) un .unmarshal(contextFile.toURI().toURL().openStream()); parseRealConfiguration(dir.getAbsolutePath(), context); } catch (Exception e) { log.error("Exception when parsing context resource {}", contextFile.getName(), e); } } } } else { log.warn("Specified context directory doesn't exists {}", directory); } }
From source file:com.opengamma.maven.scripts.ScriptableScriptGeneratorMojo.java
private static ClassLoader getResourceLoader(String resourceArtifact, MavenProject project) throws MojoExecutionException, MalformedURLException { if (StringUtils.isBlank(resourceArtifact)) { return ScriptableScriptGeneratorMojo.class.getClassLoader(); }/*from w ww . ja v a2 s .co m*/ File artifactFile = MojoUtils.getArtifactFile(resourceArtifact, project); return new URLClassLoader(new URL[] { artifactFile.toURI().toURL() }); }
From source file:bs.java
private static void loadable(String filename) { File file = new File(filename); JarInputStream is;//w w w. ja v a 2 s. c o m try { ClassLoader loader = URLClassLoader.newInstance(new URL[] { file.toURI().toURL() }); is = new JarInputStream(new FileInputStream(file)); JarEntry entry; while ((entry = is.getNextJarEntry()) != null) { if (entry.getName().endsWith(".class") && !entry.getName().contains("/")) { Class<?> cls = Class.forName(FilenameUtils.removeExtension(entry.getName()), false, loader); for (Class<?> i : cls.getInterfaces()) { if (i.equals(Loadable.class)) { Loadable l = (Loadable) cls.newInstance(); Bs.addModule(l); } } } } } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:com.doculibre.constellio.plugins.PluginFactory.java
private static void initPluginManager() { if (pm == null) { pm = PluginManagerFactory.createPluginManager(); File classesDir = ClasspathUtils.getClassesDir(); pm.addPluginsFrom(classesDir.toURI()); File pluginsDir = getPluginsDir(); File[] pluginDirs = pluginsDir.listFiles(new FileFilter() { @Override/* w w w.ja va 2s . co m*/ public boolean accept(File pathname) { boolean accept; if (pathname.isFile()) { accept = false; } else if (DefaultConstellioPlugin.NAME.equals(pathname)) { accept = true; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); accept = availablePluginNames.contains(pathname.getName()); } return accept; } }); if (pluginDirs == null) { return; } for (File pluginDir : pluginDirs) { // Plugin root dir jars Collection<File> pluginJarFiles = FileUtils.listFiles(pluginDir, new String[] { "jar" }, false); // Accept only one root dir jar File pluginJarFile = pluginJarFiles.isEmpty() ? null : pluginJarFiles.iterator().next(); if (pluginJarFile != null) { URI pluginJarFileURI = pluginJarFile.toURI(); pm.addPluginsFrom(pluginJarFileURI); PluginManagerImpl pmImpl = (PluginManagerImpl) pm; ClassPathManager classPathManager = pmImpl.getClassPathManager(); ClassLoader classLoader = ClassPathManagerUtils.getClassLoader(classPathManager, pluginJarFile); classLoaders.add(classLoader); File pluginLibDir = new File(pluginDir, "lib"); if (pluginLibDir.exists() && pluginLibDir.isDirectory()) { Collection<File> pluginDependencies = FileUtils.listFiles(pluginLibDir, new String[] { "jar" }, false); ClassPathManagerUtils.addJarDependencies(classPathManager, pluginJarFile, pluginDependencies); } } } File webInfDir = ClasspathUtils.getWebinfDir(); File libDir = new File(webInfDir, "lib"); File[] contellioJarFiles = libDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean accept; if (pathname.isDirectory()) { accept = false; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName()); accept = availablePluginNames.contains(jarNameWoutExtension); } return accept; } }); for (File constellioJarFile : contellioJarFiles) { URI constellioJarFileURI = constellioJarFile.toURI(); pm.addPluginsFrom(constellioJarFileURI); } } }
From source file:io.fabric8.maven.core.util.MavenUtil.java
private static URL pathToUrl(String path) { try {/*from w ww .j a v a 2s . c o m*/ File file = new File(path); return file.toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalArgumentException( String.format("Cannot convert %s to a an URL: %s", path, e.getMessage()), e); } }