List of usage examples for java.io File toURI
public URI toURI()
From source file:net.rptools.maptool.client.AppSetup.java
public static void installLibrary(final String libraryName, final File root) throws IOException { // Add as a resource root AppPreferences.addAssetRoot(root);/*from ww w . java2 s. com*/ if (MapTool.getFrame() != null) { MapTool.getFrame().addAssetRoot(root); // License File licenseFile = new File(root, "License.txt"); if (!licenseFile.exists()) { licenseFile = new File(root, "license.txt"); } if (licenseFile.exists()) { final File licenseFileFinal = licenseFile; EventQueue.invokeLater(new Runnable() { public void run() { try { JTextPane pane = new JTextPane(); pane.setPage(licenseFileFinal.toURI().toURL()); JOptionPane.showMessageDialog(MapTool.getFrame(), pane, "License for " + libraryName, JOptionPane.INFORMATION_MESSAGE); } catch (MalformedURLException e) { log.error("Could not load license file: " + licenseFileFinal, e); } catch (IOException e) { log.error("Could not load license file: " + licenseFileFinal, e); } } }); } } new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { AssetManager.searchForImageReferences(root, AppConstants.IMAGE_FILE_FILTER); return null; } }.execute(); }
From source file:com.cloud.utils.UriUtils.java
public static String formFileUri(String path) { File file = new File(path); return file.toURI().toString(); }
From source file:com.ejisto.util.IOUtils.java
public static URL fileToUrl(File f) { try {// www . jav a2 s.co m return f.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.qualogy.qafe.core.application.ApplicationContextLoader.java
public static void load(String applicationFilePath, boolean validating) { File file = new File(applicationFilePath); if (!file.exists()) { throw new LoadFailedException("Cannot find applicationconfig at [" + applicationFilePath + "]"); }// ww w . jav a2s . com load(file.toURI(), validating); }
From source file:com.ejisto.util.IOUtils.java
public static URL[] addServerLibs(URL[] entries, String serverLibDir) throws MalformedURLException { Collection<File> jars = getAllFiles(new File(serverLibDir), new String[] { "jar" }); URL[] ret = new URL[entries.length + jars.size()]; System.arraycopy(entries, 0, ret, 0, entries.length); int pos = entries.length; for (File jar : jars) { ret[pos++] = jar.toURI().toURL(); }//from w w w .j av a2 s .c o m return ret; }
From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java
private static void initLogging() { System.setProperty("appDir", SystemUtils.getPropertyDir().getAbsolutePath()); URL logConfigUrl = null;/*from ww w . j a va 2 s . c o m*/ File logConfigFile = new File(SystemUtils.getPropertyDir(), "/logging.properties"); if (logConfigFile.exists()) { try { logConfigUrl = logConfigFile.toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } } else { logConfigUrl = EzDL.class.getResource("/log/logging.properties"); } if (logConfigUrl != null) { PropertyConfigurator.configure(logConfigUrl); } else { System.err.println("no logger config found!"); } Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.error("Uncaught exception in Thread " + t.getName(), e); } }); System.err.close(); }
From source file:io.druid.initialization.Initialization.java
/** * @param extension The File instance of the extension we want to load * * @return a URLClassLoader that loads all the jars on which the extension is dependent * * @throws MalformedURLException//from www . j av a 2s. c o m */ public static URLClassLoader getClassLoaderForExtension(File extension) throws MalformedURLException { URLClassLoader loader = loadersMap.get(extension); if (loader == null) { final Collection<File> jars = FileUtils.listFiles(extension, new String[] { "jar" }, false); final URL[] urls = new URL[jars.size()]; int i = 0; for (File jar : jars) { final URL url = jar.toURI().toURL(); log.info("added URL[%s]", url); urls[i++] = url; } loadersMap.putIfAbsent(extension, new URLClassLoader(urls, Initialization.class.getClassLoader())); loader = loadersMap.get(extension); } return loader; }
From source file:kr.ac.kaist.wala.hybridroid.callgraph.AndroidHybridAnalysisScope.java
private static AndroidHybridAnalysisScope setUpJsAnalysisScope(String dir, AndroidHybridAnalysisScope scope, Set<URL> htmls) throws IllegalArgumentException, IOException { JavaScriptLoader.addBootstrapFile(WebUtil.preamble); if (SystemUtils.IS_OS_WINDOWS) { scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("prologue.js")) { @Override/*ww w. j a v a 2 s .co m*/ public String getName() { return "prologue.js"; } }); scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("preamble.js")) { @Override public String getName() { return "preamble.js"; } }); } else { scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("prologue.js")) { @Override public String getName() { return "prologue.js"; } }); scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("preamble.js")) { @Override public String getName() { return "preamble.js"; } }); //scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphBuilderUtil.getPrologueFile("prologue.js")); //scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphBuilderUtil.getPrologueFile("preamble.js")); } for (URL url : htmls) { try { File f = WebUtil.extractScriptFromHTML(url, DefaultSourceExtractor.factory).snd; scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(f.toURI().toURL())); String jspath = f.getCanonicalPath(); addScopeMap(Atom.findOrCreateAsciiAtom(url.toString()), Atom.findOrCreateAsciiAtom( jspath.substring(jspath.lastIndexOf(File.separator) + 1, jspath.length()))); if (DEBUG) System.err.println("#Loaded html: " + url.getFile()); } catch (Error | RuntimeException e) {// | UnimplementedError | // Error e) { if (url.toString().startsWith("http")) { System.err.println("Cannot receive the response from the url: " + url); } else { String path = url.getPath(); SourceModule dummy = new SourceURLModule(FileWriter .makeHtmlFile(dir, path.substring(path.lastIndexOf(File.separator) + 1, path.length() - 1), "") .toURI().toURL()); String dummypath = dummy.getName(); if (DEBUG) System.err.println("make dummy: " + dummypath); addScopeMap(Atom.findOrCreateAsciiAtom(url.toString()), Atom .findOrCreateAsciiAtom(dummypath.substring(dummypath.lastIndexOf(File.separator) + 1))); scope.addToScope(scope.getJavaScriptLoader(), dummy); } } } return scope; }
From source file:com.stacksync.desktop.Stacksync.java
public static void start() { Boolean deamonMode = false;/* ww w . j a v a2 s . c o m*/ Boolean extendedMode; try { try { File file = new File(env.getDefaultUserConfigDir() + File.separator + "conf" + File.separator + Constants.LOGGING_DEFAULT_FILENAME); DOMConfigurator.configure(file.toURI().toURL()); } catch (NullPointerException e) { System.out.println( "No log4j config file was found no logs will be saved for this stacksync instance please make sure LogProperties.xml file is correctly placed " + e.toString()); } catch (MalformedURLException ex) { System.out.println( "No log4j config file was found no logs will be saved for this stacksync instance please make sure LogProperties.xml file is correctly placed " + ex.toString()); } // create the command line parser Options options = createOptions(); CommandLine line = parser.parse(options, args); // Help if (line.hasOption("help")) { showHelp(options); } deamonMode = line.hasOption("daemon"); config.setDaemonMode(deamonMode); extendedMode = line.hasOption("extended"); config.setExtendedMode(extendedMode); // Load config if (line.hasOption("config")) { File configFolder = new File(line.getOptionValue("config")); File configFile = new File(line.getOptionValue("config") + File.separator + "config.xml"); if (configFolder.exists() && configFile.exists()) { config.load(configFolder); } else { if (!configFolder.exists()) { throw new ConfigException("config folder " + configFolder + " doesn't exist."); } else { throw new ConfigException(configFile + " doesn't exist."); } } if (config.getProfile() == null) { throw new ConfigException("Could not load a profile, check the configuration file."); } } else { File configurationDir = env.getAppConfDir(); if (configurationDir.exists()) { config.load(); if (config.getProfile() == null) { File folder = new File( config.getConfDir() + File.separator + Constants.CONFIG_DATABASE_DIRNAME); File configFile = new File( config.getConfDir() + File.separator + Constants.CONFIG_FILENAME); folder.delete(); configFile.delete(); config.load(); } } else { // new configuration config.load(); } } } catch (ConfigException e) { System.err.println("ERROR: Configuration exception: "); System.err.println(StringUtil.getStackTrace(e)); System.exit(1); } catch (ParseException e) { System.err.println("ERROR: Command line arguments invalid: "); System.err.println(StringUtil.getStackTrace(e)); System.exit(1); } // Start app! try { // TODO fixit //RemoteLogs.sendFailedLogs(); Application appStacksync = new Application(); appStacksync.start(); } catch (Exception e) { if (!deamonMode) { ErrorDialog.showDialog(e); } } }
From source file:com.sap.hana.cloud.samples.jenkins.plugin.uitests.CloudJenkinsPluginTest.java
static Set<String> findAllFiles(final File root) { final Set<String> result = new HashSet<String>(); for (final Object object : FileUtils.listFiles(root, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())) { result.add(root.toURI().relativize(((File) object).toURI()).toString()); }// w w w .java 2s. c o m return result; }