List of usage examples for java.io File toURL
@Deprecated public URL toURL() throws MalformedURLException
file:
URL. From source file:org.wso2.ei.businessprocess.utils.migration.MigrationExecutor.java
private static void addPath(String s) throws Exception { File f = new File(s); URL u = f.toURL(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<URLClassLoader> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", URL.class); method.setAccessible(true);//from www. j a v a 2 s . co m method.invoke(urlClassLoader, u); }
From source file:Which4J.java
/** * Iterate over the system classpath defined by "java.class.path" searching * for all occurrances of the given class name. * /*from ww w.j ava 2 s . c o m*/ * @param classname the fully qualified class name to search for */ private static void findIt(String classname) { try { // get the system classpath String classpath = System.getProperty("java.class.path", ""); if (classpath.equals("")) { System.err.println("error: classpath is not set"); } if (debug) { System.out.println("classname: " + classname); System.out.println("system classpath = " + classpath); } if (isPrimitiveOrVoid(classname)) { System.out.println("'" + classname + "' primitive"); return; } StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); while (st.hasMoreTokens()) { String token = st.nextToken(); File classpathElement = new File(token); if (debug) System.out.println(classpathElement.isDirectory() ? "dir: " + token : "jar: " + token); URL[] url = { classpathElement.toURL() }; URLClassLoader cl = URLClassLoader.newInstance(url, null); String classnameAsResource = classname.replace('.', '/') + ".class"; URL it = cl.findResource(classnameAsResource); if (it != null) { System.out.println("found in: " + token); System.out.println(" url: " + it.toString()); System.out.println(""); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:SerialVersionUID.java
static void buildJarSet(File dir, HashSet jarFiles) throws MalformedURLException { File[] files = dir.listFiles(); int count = files != null ? files.length : 0; System.out.println("Checking dir: " + dir + ", count=" + count); for (int n = 0; n < count; n++) { File child = files[n]; // Ignore the server tmp directory if (child.isDirectory() && child.getName().equals("tmp") == false) buildJarSet(child, jarFiles); else if (child.getName().endsWith(".jar")) jarFiles.add(child.toURL()); }/*from w w w .ja va 2s . co m*/ }
From source file:org.mbari.aved.ui.classifier.ClassModelListRenderer.java
/** * Returns an ImageIcon, or null if the path was invalid. *//*ww w . j a v a 2 s .c o m*/ public static ImageIcon createImageIcon(URL imageUrl) { try { if (imageUrl != null) { String fileName = imageUrl.getFile(); String extension = ""; int i = fileName.lastIndexOf('.'); if (i > 0) { extension = fileName.substring(i + 1).toUpperCase(); } if (extension.equals("GIF") || extension.equals("JPG") || extension.equals("PNG")) return new ImageIcon(imageUrl); else { File tmproot = ErrorLog.getInstance().getLogRoot(); String basename = FilenameUtils.getBaseName(imageUrl.getFile()); File output = new File(tmproot + "/" + basename + ".jpg"); if (!output.exists()) { BufferedImage image = ImageIO.read(imageUrl); ImageIO.write(image, "jpg", output); } return new ImageIcon(output.toURL()); } } else { System.err.println("Couldn't find image: " + imageUrl.getPath()); } } catch (Exception ex) { Logger.getLogger(ClassModelListRenderer.class.getName()).log(Level.SEVERE, "Error creating image icon for " + imageUrl.getPath(), ex); } return null; }
From source file:org.apache.axis2.jaxbri.CodeGenerationUtility.java
private static void scanEpisodeFile(File jar, SchemaCompiler sc) throws BadCommandLineException, IOException { URLClassLoader ucl = new URLClassLoader(new URL[] { jar.toURL() }); Enumeration<URL> resources = ucl.findResources("META-INF/sun-jaxb.episode"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); sc.getOptions().addBindFile(new InputSource(url.toExternalForm())); }//w w w. j av a2 s . c o m }
From source file:org.deegree.framework.util.ImageUtils.java
/** * reads an image from the passed file location using JAI mechanism * * @param file/*from ww w.j a va 2 s. c o m*/ * * @return read image * * @throws IOException */ public static BufferedImage loadImage(File file) throws IOException { BufferedImage img = null; String tmp = file.getName().toLowerCase(); if (tmp.endsWith(".tif") || tmp.endsWith(".tiff")) { InputStream is = file.toURL().openStream(); org.apache.batik.ext.awt.image.codec.SeekableStream fss = new org.apache.batik.ext.awt.image.codec.MemoryCacheSeekableStream( is); TIFFImage tiff = new TIFFImage(fss, new TIFFDecodeParam(), 0); img = PlanarImage.wrapRenderedImage(tiff).getAsBufferedImage(); fss.close(); } else if (tmp.endsWith(".png")) { InputStream is = file.toURL().openStream(); ImageDecoderImpl dec = new PNGImageDecoder(is, new PNGDecodeParam()); img = PlanarImage.wrapRenderedImage(dec.decodeAsRenderedImage()).getAsBufferedImage(); is.close(); } else { img = ImageIO.read(file); } return img; }
From source file:org.wso2.carbon.micro.integrator.server.Main.java
/** * buildInitialPropertyMap create the initial set of properties from the contents of launch.ini * and for a few other properties necessary to launch defaults are supplied if not provided. * The value '@null' will set the map value to null. * * @return a map containing the initial properties */// w w w. j ava2 s .co m private static Map<String, String> buildInitialPropertyMap() { Map<String, String> initialPropertyMap = new HashMap<String, String>(); String carbonConfigHome = System.getProperty(LauncherConstants.CARBON_CONFIG_DIR_PATH); Properties launchProperties; if (carbonConfigHome == null) { String carbonHome = System.getProperty(LauncherConstants.CARBON_HOME); launchProperties = Utils.loadProperties( Paths.get(carbonHome, "repository", "conf", "etc", LauncherConstants.LAUNCH_INI).toString()); } else { launchProperties = Utils .loadProperties(Paths.get(carbonConfigHome, "etc", LauncherConstants.LAUNCH_INI).toString()); } for (Object o : launchProperties.entrySet()) { Map.Entry entry = (Map.Entry) o; String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (key.endsWith("*")) { //$NON-NLS-1$ if (value.equals(NULL_IDENTIFIER)) { Utils.clearPrefixedSystemProperties(key.substring(0, key.length() - 1), initialPropertyMap); } } else if (value.equals(NULL_IDENTIFIER)) { initialPropertyMap.put(key, null); } else { initialPropertyMap.put((String) entry.getKey(), (String) entry.getValue()); } } try { /* * in order to support multiple profiling, the new install, configuration and workspace area got to move * from ../components/ to ../components/ PROFILE_ID/ */ // install.area if not specified if (initialPropertyMap.get(OSGI_INSTALL_AREA) == null) { //specifying the install.area according to the running Profile File installDir = new File(platformDirectory, System.getProperty(LauncherConstants.PROFILE_ID)); initialPropertyMap.put(OSGI_INSTALL_AREA, installDir.toURL().toExternalForm()); } // configuration.area if not specified if (initialPropertyMap.get(OSGI_CONFIGURATION_AREA) == null) { File configurationDirectory = new File(platformDirectory, System.getProperty(LauncherConstants.PROFILE_ID) + File.separator + "configuration"); initialPropertyMap.put(OSGI_CONFIGURATION_AREA, configurationDirectory.toURL().toExternalForm()); } // instance.area if not specified if (initialPropertyMap.get(OSGI_INSTANCE_AREA) == null) { File workspaceDirectory = new File(platformDirectory, System.getProperty(LauncherConstants.PROFILE_ID) + File.separator + "workspace"); initialPropertyMap.put(OSGI_INSTANCE_AREA, workspaceDirectory.toURL().toExternalForm()); } // osgi.framework if not specified if (initialPropertyMap.get(OSGI_FRAMEWORK) == null) { // search for osgi.framework in osgi.install.area /*String installArea = initialPropertyMap.get(OSGI_INSTALL_AREA); // only support file type URLs for install area if (installArea.startsWith(FILE_SCHEME)) { installArea = installArea.substring(FILE_SCHEME.length()); } String path = new File(installArea, "plugins").toString();*/ String path = new File(platformDirectory, "plugins").toString(); path = Utils.searchFor(FRAMEWORK_BUNDLE_NAME, path); if (path == null) { throw new RuntimeException("Could not find framework"); } initialPropertyMap.put(OSGI_FRAMEWORK, new File(path).toURL().toExternalForm()); } if (initialPropertyMap.get(P2_DATA_AREA) == null) { /*initialPropertyMap.put(P2_DATA_AREA, new File(platformDirectory, System.getProperty(LauncherConstants.PROFILE_ID) + File.separator + "p2").toString());*/ initialPropertyMap.put(P2_DATA_AREA, new File(platformDirectory, "p2").toString()); //System.out.println("the data area: " + initialPropertyMap.get(P2_DATA_AREA)); } } catch (MalformedURLException e) { throw new RuntimeException("Error establishing location"); } return initialPropertyMap; }
From source file:org.ops4j.pax.url.maven.commons.MavenSettingsImpl.java
/** * Looks for the file denoted by file path and returns the corresponding file if the file exists, is a file and can * be read. Otherwise returns null.//from w w w . ja va2 s . co m * * @param filePath the path to the file * * @return the file denoted by the file path if can be read or null otherwise */ private static URL safeGetFile(final String filePath) { if (filePath != null) { File file = new File(filePath); if (file.exists() && file.canRead() && file.isFile()) { try { return file.toURL(); } catch (MalformedURLException e) { // do nothing } } } return null; }
From source file:org.eclipse.thym.core.internal.util.FileUtils.java
/** * Convenience method to turn a file to a URL. * May return null if it can not create a URL from the file passed or file is null. * /*from w w w.java 2 s .co m*/ * @param file * @return */ public static URL toURL(File file) { if (file == null) return null; try { return file.toURL(); } catch (MalformedURLException e) { return null; } }
From source file:org.fusesource.fabric.agent.mvn.MavenSettingsImpl.java
private static URL safeGetFile(final String filePath) { if (filePath != null) { File file = new File(filePath); if (file.exists() && file.canRead() && file.isFile()) { try { return file.toURL(); } catch (MalformedURLException e) { // do nothing }/*from ww w . j a v a 2 s. co m*/ } } return null; }