List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:com.ms.commons.test.common.FileUtil.java
@SuppressWarnings("deprecation") public static List<URL> convertFileListToUrlList(List<File> fileList) { List<URL> urlList = new ArrayList<URL>(fileList.size()); for (File f : fileList) { try {//from w w w . j a v a 2s. c om urlList.add(f.toURL()); } catch (MalformedURLException e) { throw ExceptionUtil.wrapToRuntimeException(e); } } return urlList; }
From source file:org.apache.xml.security.samples.encryption.Encrypter.java
private static SecretKey GenerateAndStoreKeyEncryptionKey() throws Exception { String jceAlgorithmName = "DESede"; KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName); SecretKey kek = keyGenerator.generateKey(); byte[] keyBytes = kek.getEncoded(); File kekFile = new File("kek"); FileOutputStream f = new FileOutputStream(kekFile); f.write(keyBytes);//from w ww . ja v a 2s . c o m f.close(); System.out.println("Key encryption key stored in " + kekFile.toURL().toString()); return kek; }
From source file:net.ontopia.topicmaps.utils.ImportExportUtils.java
/** * PUBLIC: Given a file reference to a topic map, returns a topic * map reader of the right class. Uses the file extension to * determine what reader to create. Supports '.xtm', and '.ltm'. * /*from w w w . j av a2s. c o m*/ * @since 2.0 */ public static TopicMapReaderIF getReader(java.io.File file) throws java.io.IOException { return getReader(file.toURL().toExternalForm()); }
From source file:org.sakaiproject.james.PhoenixLauncherMain.java
/** * Create a ClassPath for the engine.//ww w . j ava 2 s. co m * * @return the set of URLs that engine uses to load * @throws Exception * if unable to aquire classpath */ private static URL[] getEngineClassPath() throws Exception { final ArrayList urls = new ArrayList(); final File dir = findEngineLibDir(); final File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { final File file = files[i]; if (file.getName().endsWith(".jar")) { urls.add(file.toURL()); } } // TODO: (done) add also the phoenix libs final File dir_p = findPhoenixLibDir(); final File[] files_p = dir_p.listFiles(); for (int i = 0; i < files_p.length; i++) { final File file = files_p[i]; if (file.getName().endsWith(".jar")) { urls.add(file.toURL()); } } return (URL[]) urls.toArray(new URL[urls.size()]); }
From source file:eu.stratosphere.yarn.Utils.java
private static void addPathToConfig(Configuration conf, File path) { // chain-in a new classloader URL fileUrl = null;// w w w .java2 s.com try { fileUrl = path.toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Erroneous config file path", e); } URL[] urls = { fileUrl }; ClassLoader cl = new URLClassLoader(urls, conf.getClassLoader()); conf.setClassLoader(cl); }
From source file:com.ms.commons.test.tool.util.AutoImportProjectTaskUtil.java
@SuppressWarnings({ "unchecked", "deprecation" }) public static Task wrapAutoImportTask(final File project, final Task oldTask) { InputStream fis = null;/*from ww w . j ava 2s . c o m*/ try { fis = new BufferedInputStream(project.toURL().openStream()); SAXBuilder b = new SAXBuilder(); Document document = b.build(fis); List<Element> elements = XPath.selectNodes(document, "/project/build/dependencies/include"); List<String> addList = new ArrayList<String>(importList); if (elements != null) { for (Element ele : elements) { String uri = ele.getAttribute("uri").getValue().trim().toLowerCase(); if (importList.contains(uri)) { addList.remove(uri); } } } if (addList.size() > 0) { System.err.println("Add projects:" + addList); List<Element> testElements = XPath.selectNodes(document, "/project/build[@profile='TEST']/dependencies"); Element testEle; if ((testElements == null) || (testElements.size() == 0)) { Element buildEle = new Element("build"); buildEle.setAttribute("profile", "TEST"); Element filesetsEle = new Element("filesets"); filesetsEle.setAttribute("name", "java.resdirs"); Element excludeEle = new Element("exclude"); excludeEle.setAttribute("fileset", "java.configdir"); filesetsEle.addContent(excludeEle); testEle = new Element("dependencies"); buildEle.addContent(Arrays.asList(filesetsEle, testEle)); ((Element) XPath.selectNodes(document, "/project").get(0)).addContent(buildEle); } else { testEle = testElements.get(0); } for (String add : addList) { Element e = new Element("include"); e.setAttribute("uri", add); testEle.addContent(e); } String newF = project.getAbsolutePath() + ".new"; XMLOutputter xmlOutputter = new XMLOutputter(); Writer writer = new BufferedWriter(new FileWriter(newF)); xmlOutputter.output(document, writer); writer.flush(); FileUtil.closeCloseAbleQuitly(writer); final File newFile = new File(newF); return new Task() { public void finish() { boolean hasError = false; File backUpFile = new File(project.getAbsoluteFile() + ".backup"); try { FileUtils.copyFile(project, backUpFile); FileUtils.copyFile(newFile, project); oldTask.finish(); } catch (Exception e) { hasError = true; e.printStackTrace(); } finally { try { FileUtils.copyFile(backUpFile, project); } catch (IOException e) { hasError = true; e.printStackTrace(); } newFile.delete(); backUpFile.delete(); } if (hasError) { System.exit(-1); } } }; } return oldTask; } catch (Exception e) { throw new RuntimeException(e); } finally { FileUtil.closeCloseAbleQuitly(fis); } }
From source file:org.n52.oxf.util.IOHelper.java
public static String readText(File file) throws IOException { return readText(file.toURL()); }
From source file:org.onosproject.rabbitmq.util.MQUtil.java
/** * Handles load mq property file from resources and returns Properties. * * @param context the component context * @return the mq server properties * @throws RuntimeException if property file not found. *///from www . j a v a2 s . c o m public static Properties getProp(ComponentContext context) { URL configUrl; try { configUrl = context.getBundleContext().getBundle().getResource(MQ_PROP_NAME); } catch (Exception ex) { // This will be used only during junit test case since bundle // context will be available during runtime only. File file = new File(MQUtil.class.getClassLoader().getResource(MQ_PROP_NAME).getFile()); try { configUrl = file.toURL(); } catch (MalformedURLException e) { log.error(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e); } } Properties properties; try { InputStream is = configUrl.openStream(); properties = new Properties(); properties.load(is); } catch (Exception e) { log.error(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e); } return properties; }
From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java
@SuppressWarnings("deprecation") private static ConnectorRegistry create(ApplicationConfig config) throws Exception { Map<String, String> paramValues = config.getParamValues(); String appId = config.getApplicationId(); String connectorId = (String) paramValues.get("connectorId"); File file1 = new File(CoreUtils.getConnectorDir() + File.separatorChar + connectorId); URL[] urls = new URL[] { file1.toURL() }; ClassLoader cl = ClassLoaderRepository.getClassLoader(urls, true); //URLClassLoader cl = new URLClassLoader(urls, // ConnectorMBeanRegistry.class.getClassLoader()); Registry.MODELER_MANIFEST = MBEANS_DESCRIPTOR; URL res = cl.getResource(MBEANS_DESCRIPTOR); logger.info("Application ID : " + appId); logger.info("Connector Archive: " + file1.getAbsoluteFile()); logger.info("MBean Descriptor : " + res.toString()); //Thread.currentThread().setContextClassLoader(cl); //Registry.setUseContextClassLoader(true); ConnectorRegistry registry = new ConnectorRegistry(); registry.loadMetadata(cl);//from w ww . ja v a2 s . com String[] mbeans = registry.findManagedBeans(); MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR); for (int i = 0; i < mbeans.length; i++) { ManagedBean managed = registry.findManagedBean(mbeans[i]); String clsName = managed.getType(); String domain = managed.getDomain(); if (domain == null) { domain = DOMAIN_CONNECTOR; } Class<?> cls = Class.forName(clsName, true, cl); Object objMBean = null; // Use the factory method when it is defined. Method[] methods = cls.getMethods(); for (Method method : methods) { if (method.getName().equals(FACTORY_METHOD) && Modifier.isStatic(method.getModifiers())) { objMBean = method.invoke(null); logger.info("Create MBean using factory method."); break; } } if (objMBean == null) { objMBean = cls.newInstance(); } // Call the initialize method if the MBean extends ConnectorSupport class if (objMBean instanceof ConnectorSupport) { Method method = cls.getMethod("initialize", new Class[] { Map.class }); Map<String, String> props = config.getParamValues(); method.invoke(objMBean, new Object[] { props }); } ModelMBean mm = managed.createMBean(objMBean); String beanObjName = domain + ":name=" + mbeans[i]; server.registerMBean(mm, new ObjectName(beanObjName)); } registry.setMBeanServer(server); entries.put(appId, registry); return registry; }
From source file:org.bigbluebuttonproject.fileupload.document.impl.Helper.java
/** * Creating a correct File URL that OpenOffice can handle. This is * necessary to be platform independent. * //from ww w . j a v a 2s. c o m * @param filelocation the filelocation * @param componentContext the component context * * @return the string */ public static String createUNOFileURL(XComponentContext componentContext, String filelocation) { java.io.File newfile = new java.io.File(filelocation); java.net.URL before = null; try { before = newfile.toURL(); } catch (MalformedURLException e) { logger.error(e); } // Create a URL, which can be used by UNO String myUNOFileURL = com.sun.star.uri.ExternalUriReferenceTranslator.create(componentContext) .translateToInternal(before.toExternalForm()); if (myUNOFileURL.length() == 0 && filelocation.length() > 0) { logger.error( "File URL conversion failed. Filelocation " + "contains illegal characters: " + filelocation); } logger.warn("UNOFileURL = " + myUNOFileURL); return myUNOFileURL; }