List of usage examples for java.io File toURI
public URI toURI()
From source file:com.mirth.connect.server.util.SqlConfig.java
private static void addPluginSqlMaps(String database, DonkeyElement sqlMapConfigElement) throws Exception { ExtensionController extensionController = ControllerFactory.getFactory().createExtensionController(); Map<String, PluginMetaData> plugins = extensionController.getPluginMetaData(); if (MapUtils.isNotEmpty(plugins)) { for (String pluginName : plugins.keySet()) { PluginMetaData pmd = plugins.get(pluginName); if (extensionController.isExtensionEnabled(pluginName)) { // only add configs for plugins that have some configs defined if (pmd.getSqlMapConfigs() != null) { /* get the SQL map for the current database */ String pluginSqlMapName = pmd.getSqlMapConfigs().get(database); if (StringUtils.isBlank(pluginSqlMapName)) { /* * if we couldn't find one for the current * database, check for one that works with * all databases *///w ww. j a va 2s .co m pluginSqlMapName = pmd.getSqlMapConfigs().get("all"); } if (StringUtils.isNotBlank(pluginSqlMapName)) { File sqlMapConfigFile = new File( ExtensionController.getExtensionsPath() + pmd.getPath(), pluginSqlMapName); Element sqlMapElement = sqlMapConfigElement.addChildElement("mapper"); sqlMapElement.setAttribute("url", sqlMapConfigFile.toURI().toURL().toString()); } else { throw new RuntimeException("SQL map file not found for database: " + database); } } } } } }
From source file:com.marklogic.contentpump.ContentPump.java
private static void submitJob(Job job) throws Exception { String cpHome = System.getProperty(CONTENTPUMP_HOME_PROPERTY_NAME); // find job jar File cpHomeDir = new File(cpHome); FilenameFilter jobJarFilter = new FilenameFilter() { @Override// www. jav a 2 s. c om public boolean accept(File dir, String name) { if (name.endsWith(".jar") && name.startsWith(CONTENTPUMP_JAR_PREFIX)) { return true; } else { return false; } } }; File[] cpJars = cpHomeDir.listFiles(jobJarFilter); if (cpJars == null || cpJars.length == 0) { throw new RuntimeException("Content Pump jar file " + "is not found under " + cpHome); } if (cpJars.length > 1) { throw new RuntimeException("More than one Content Pump jar file " + "are found under " + cpHome); } // set job jar Configuration conf = job.getConfiguration(); conf.set("mapreduce.job.jar", cpJars[0].toURI().toURL().toString()); // find lib jars FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.endsWith(".jar") && !name.startsWith("hadoop")) { return true; } else { return false; } } }; // set lib jars StringBuilder jars = new StringBuilder(); for (File jar : cpHomeDir.listFiles(filter)) { if (jars.length() > 0) { jars.append(','); } jars.append(jar.toURI().toURL().toString()); } conf.set("tmpjars", jars.toString()); if (LOG.isTraceEnabled()) LOG.trace("LIBJARS:" + jars.toString()); job.waitForCompletion(true); AuditUtil.auditMlcpFinish(conf, job.getJobName(), job.getCounters()); }
From source file:io.fabric8.apiman.ApimanStarter.java
public static void setFabric8Props(URL elasticEndpoint) throws IOException { log.info("** Setting API Manager Configuration Properties **"); setConfigProp("apiman.plugins.repositories", "http://repository.jboss.org/nexus/content/groups/public/"); setConfigProp("apiman.es.protocol", elasticEndpoint.getProtocol()); setConfigProp("apiman.es.host", elasticEndpoint.getHost()); setConfigProp("apiman.es.port", String.valueOf(elasticEndpoint.getPort())); String esIndexPrefix = getSystemPropertyOrEnvVar("apiman.es.index.prefix", ".apiman_"); if (esIndexPrefix != null) { setConfigProp(ApiManagerConfig.APIMAN_MANAGER_STORAGE_ES_INDEX_NAME, esIndexPrefix + "manager"); }//from www . j a v a 2 s. c o m setConfigProp(ApiManagerConfig.APIMAN_MANAGER_STORAGE_ES_CLIENT_FACTORY, Fabric8EsClientFactory.class.getName()); setConfigProp(ApiManagerConfig.APIMAN_MANAGER_STORAGE_TYPE, "es"); setConfigProp("apiman-manager.storage.es.protocol", Systems.getEnvVarOrSystemProperty("apiman.es.protocol")); setConfigProp("apiman-manager.storage.es.host", Systems.getEnvVarOrSystemProperty("apiman.es.host")); setConfigProp("apiman-manager.storage.es.port", Systems.getEnvVarOrSystemProperty("apiman.es.port")); setConfigProp("apiman-manager.storage.es.username", Systems.getEnvVarOrSystemProperty("apiman.es.username")); setConfigProp("apiman-manager.storage.es.password", Systems.getEnvVarOrSystemProperty("apiman.es.password")); setConfigProp(ApiManagerConfig.APIMAN_MANAGER_STORAGE_ES_INITIALIZE, "true"); setConfigProp(ApiManagerConfig.APIMAN_MANAGER_METRICS_TYPE, "es"); setConfigProp("apiman-manager.metrics.es.protocol", Systems.getEnvVarOrSystemProperty("apiman.es.protocol")); setConfigProp("apiman-manager.metrics.es.host", Systems.getEnvVarOrSystemProperty("apiman.es.host")); setConfigProp("apiman-manager.metrics.es.port", Systems.getEnvVarOrSystemProperty("apiman.es.port")); setConfigProp("apiman-manager.metrics.es.username", Systems.getEnvVarOrSystemProperty("apiman.es.username")); setConfigProp("apiman-manager.metrics.es.password", Systems.getEnvVarOrSystemProperty("apiman.es.password")); setConfigProp(ApiManagerConfig.APIMAN_MANAGER_API_CATALOG_TYPE, KubernetesServiceCatalog.class.getName()); File gatewayUserFile = new File(ApimanStarter.APIMAN_GATEWAY_USER_PATH); if (gatewayUserFile.exists()) { String[] user = IOUtils.toString(gatewayUserFile.toURI()).split(","); setConfigProp(ApimanStarter.APIMAN_GATEWAY_USERNAME, user[0]); setConfigProp(ApimanStarter.APIMAN_GATEWAY_PASSWORD, user[1]); } log.info("** ******************************************** **"); }
From source file:com.t3.persistence.FileUtil.java
/** * Returns a Reader from the given <code>File</code> object. * /*w ww . jav a 2 s . c o m*/ * @param file the input data source * @return a String representing the data * @throws IOException */ public static Reader getFileAsReader(File file) throws IOException { return getURLAsReader(file.toURI().toURL()); }
From source file:com.ts.db.connector.ConnectorDriverManager.java
static Driver getDriver(String url, String driverClassName, String classpath) throws SQLException { assert !StringUtils.isBlank(url); final boolean hasClasspath = !StringUtils.isBlank(classpath); if (!hasClasspath) { for (Driver driver : new ArrayList<Driver>(drivers)) { if (driver.acceptsURL(url)) { return driver; }/* w ww .j a va2s. c om*/ } } List<File> jars = new ArrayList<File>(); ClassLoader cl; if (hasClasspath) { List<URL> urls = new ArrayList<URL>(); for (String path : classpath.split(pathSeparator)) { final File file = new File(path); if (isJarFile(file)) { jars.add(file); } try { urls.add(file.toURI().toURL()); } catch (MalformedURLException ex) { log.warn(ex.toString()); } } cl = new URLClassLoader(urls.toArray(new URL[urls.size()])); } else { jars.addAll(getJarFiles(".")); jars.addAll(driverFiles); List<URL> urls = new ArrayList<URL>(); for (File file : jars) { try { urls.add(file.toURI().toURL()); } catch (MalformedURLException ex) { log.warn(ex.toString()); } } cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), ClassLoader.getSystemClassLoader()); } driverFiles.addAll(jars); final boolean hasDriverClassName = !StringUtils.isBlank(driverClassName); if (hasDriverClassName) { try { Driver driver = DynamicLoader.newInstance(driverClassName, cl); assert driver != null; return driver; } catch (DynamicLoadingException ex) { Throwable cause = (ex.getCause() != ex) ? ex.getCause() : ex; SQLException exception = new SQLException(cause.toString()); exception.initCause(cause); throw exception; } } final String jdbcDrivers = System.getProperty("jdbc.drivers"); if (!StringUtils.isBlank(jdbcDrivers)) { for (String jdbcDriver : jdbcDrivers.split(":")) { try { Driver driver = DynamicLoader.newInstance(jdbcDriver, cl); if (driver != null) { if (!hasClasspath) { drivers.add(driver); } return driver; } } catch (DynamicLoadingException ex) { log.warn(ex.toString()); } } } for (File jar : jars) { try { Driver driver = getDriver(jar, url, cl); if (driver != null) { if (!hasClasspath) { drivers.add(driver); } return driver; } } catch (IOException ex) { log.warn(ex.toString()); } } for (String path : System.getProperty("java.class.path", "").split(pathSeparator)) { if (isJarFile(path)) { Driver driver; try { driver = getDriver(new File(path), url, cl); if (driver != null) { drivers.add(driver); return driver; } } catch (IOException ex) { log.warn(ex.toString()); } } } throw new SQLException("driver not found"); }
From source file:com.t3.persistence.FileUtil.java
/** * Given a URL this method tries to figure out what the content type might be based * only on the filename extension./*w ww.java 2 s .c o m*/ * * @param url the URL to check * @return a <code>String</code> representing the content type name */ public static String getContentType(File file) { try { return getContentType(file.toURI().toURL()); } catch (MalformedURLException e) { return null; } }
From source file:com.t3.persistence.FileUtil.java
public static InputStream getFileAsInputStream(File file) throws IOException { return getURLAsInputStream(file.toURI().toURL()); }
From source file:ClasspathUtils.java
public static void addJarToPath(final File jar) throws Exception { addJarToPath(jar.toURI().toURL()); }
From source file:de.tudarmstadt.ukp.clarin.webanno.api.dao.ZipUtils.java
private static void addToZip(ZipOutputStream zip, File aBasePath, File aPath) throws IOException { if (aPath.isDirectory()) { for (File file : aPath.listFiles()) { addToZip(zip, aBasePath, file); }/*w w w . j a v a 2 s. c o m*/ } else { FileInputStream in = null; try { in = new FileInputStream(aPath); String relativePath = aBasePath.toURI().relativize(aPath.toURI()).getPath(); zip.putNextEntry(new ZipEntry(relativePath)); IOUtils.copy(in, zip); } finally { closeQuietly(in); } } }
From source file:ClasspathUtils.java
/** * Appends the jar to the classpath of the classloader passed in. * * @param url the URL to be added to the search path of URLs */// ww w .j a v a 2s . c o m public static void addJarToSystemPath(final File jar) throws Exception { addJarToSystemPath(jar.toURI().toURL()); }