List of usage examples for java.io File toURI
public URI toURI()
From source file:io.apiman.gateway.platforms.war.micro.Users.java
/** * @throws Exception /*from ww w . ja v a2 s .c o m*/ */ private static URL getUsersUrl() throws Exception { String usersLoc = System.getProperty(USERS_FILE_PROP); if (usersLoc == null) { return null; } // Try a file first. try { File usersFile = new File(usersLoc); if (usersFile.isFile()) { return usersFile.toURI().toURL(); } } catch (Exception e) { } // Try it as a URL. URL url = new URL(usersLoc); return url; }
From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java
private static void addSharedLibsToClasspath(List<URL> urls) throws Exception { IOFileFilter sharedLibFileFilter = new WildcardFileFilter("*-shared.jar"); File extensions = new File("./extensions"); if (extensions.exists() && extensions.isDirectory()) { Collection<File> sharedLibs = FileUtils.listFiles(extensions, sharedLibFileFilter, FileFilterUtils.trueFileFilter()); for (File sharedLib : sharedLibs) { logger.trace("adding library to classpath: " + sharedLib.getAbsolutePath()); urls.add(sharedLib.toURI().toURL()); }// w w w . j a v a2s.co m } else { logger.warn("no extensions found"); } }
From source file:bluej.collect.CollectUtility.java
/** * Gets the path of the given file, relative to the given project's base directory *///from ww w . ja va 2 s . c om static String toPath(ProjectDetails proj, File f) { return proj.projectDir.toURI().relativize(f.toURI()).getPath(); }
From source file:ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory.java
private static URL[] toUrls(List<File> ivyEngineClassPathFiles) throws MalformedURLException { List<URL> classPathUrls = new ArrayList<>(); for (File file : ivyEngineClassPathFiles) { classPathUrls.add(new URL(file.toURI().toASCIIString())); }//from w w w .j av a2 s. c om return classPathUrls.toArray(new URL[classPathUrls.size()]); }
From source file:ccm.pay2spawn.configurator.HTMLGenerator.java
public static String readFile(File file) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(file.toURI())); return Charset.defaultCharset().decode(ByteBuffer.wrap(encoded)).toString(); }
From source file:dyco4j.instrumentation.internals.CLI.java
private static void addEntryToClassPath(final URLClassLoader urlClassLoader, final Method method, final String s) { final File _f = new File(s); try {//from ww w . j a va2 s. c om final URL _u = _f.toURI().toURL(); method.invoke(urlClassLoader, _u); LOGGER.info(MessageFormat.format("Adding {0} to classpath", s)); } catch (MalformedURLException | IllegalAccessException | InvocationTargetException _e) { throw new RuntimeException(_e); } }
From source file:com.shadwelldacunha.byteswipe.core.Utilities.java
public static String readFileAsString(File file, Charset encoding) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(file.toURI())); return new String(encoded, encoding); }
From source file:com.hp.mqm.atrf.Main.java
private static void configureLog4J() { //set process Id on local RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); String pid = rt.getName();//from w w w. j av a 2 s. c om ThreadContext.put("PID", pid); String log4jConfiguration = System.getProperty("log4j.configuration"); if (StringUtils.isEmpty(log4jConfiguration)) { //try to take from file File f = new File("log4j2.xml"); URI uri = null; if (f.exists() && !f.isDirectory() && f.canRead()) { uri = f.toURI(); } else { //take it from resources try { uri = Main.class.getClassLoader().getResource("log4j2.xml").toURI(); } catch (URISyntaxException e) { logger.info("Failed to load Log4j configuration from resource file"); } } LoggerContext context = (LoggerContext) LogManager.getContext(false); context.setConfigLocation(uri); //logger.info("Log4j configuration loaded from " + uri.toString()); } else { logger.info("Log4j configuration is loading from log4j.configuration=" + log4jConfiguration); } }
From source file:com.rk.grid.cluster.slave.NodeMain.java
/** * @return/* ww w. ja v a 2 s . c om*/ * @throws MalformedURLException */ private static ClassLoader getClassLoader(String pathname) throws MalformedURLException { // { // URLClassLoader loader = new URLClassLoader(new URL[] { new URL("jar:file:/C:\\temp\\Caf1.jar!/") }); // } { File file = new File(pathname); if (!file.exists()) throw new RuntimeException("File not find: " + pathname); URL[] urls = { file.toURI().toURL() }; final URLClassLoader urlClassLoader = URLClassLoader.newInstance(urls); return urlClassLoader; } }
From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java
private static void addManifestToClasspath(ManifestEntry[] manifestEntries, List<URL> urls) throws Exception { for (ManifestEntry manifestEntry : manifestEntries) { File manifestEntryFile = new File(manifestEntry.getName()); if (manifestEntryFile.exists()) { if (manifestEntryFile.isDirectory()) { ManifestDirectory manifestDir = (ManifestDirectory) manifestEntry; IOFileFilter fileFilter = null; if (manifestDir.getExcludes().length > 0) { fileFilter = FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.notFileFilter(new NameFileFilter(manifestDir.getExcludes()))); } else { fileFilter = FileFilterUtils.fileFileFilter(); }/*from w ww . j av a2 s .co m*/ Collection<File> pathFiles = FileUtils.listFiles(manifestEntryFile, fileFilter, FileFilterUtils.trueFileFilter()); for (File pathFile : pathFiles) { logger.trace("adding library to classpath: " + pathFile.getAbsolutePath()); urls.add(pathFile.toURI().toURL()); } } else { logger.trace("adding library to classpath: " + manifestEntryFile.getAbsolutePath()); urls.add(manifestEntryFile.toURI().toURL()); } } else { logger.warn("manifest path not found: " + manifestEntryFile.getAbsolutePath()); } } }