Java Code Examples for java.io.File#toURL()

The following examples show how to use java.io.File#toURL() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdiLoadedByCustomLoader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create files from given arguments and tools.jar
    File f1 = new File(args[0]);
    String home = System.getProperty("java.home");
    String tools = ".." + File.separatorChar + "lib" +
        File.separatorChar + "tools.jar";
    File f2 = (new File(home, tools)).getCanonicalFile();

    // create class loader
    URL[] urls = { f1.toURL(), f2.toURL() };
    URLClassLoader cl = new URLClassLoader(urls);

    // load ListConnectors using the class loader
    // and then invoke the list method.
    Class c = Class.forName("ListConnectors", true, cl);
    Method m = c.getDeclaredMethod("list");
    Object o = c.newInstance();
    m.invoke(o);
}
 
Example 2
Source File: OctaneTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Double genericNashornTest(final String benchmark, final String testPath, final String[] args) throws Throwable {
    try {
        final PerformanceWrapper wrapper = new PerformanceWrapper();

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final PrintStream ps = new PrintStream(baos);

        final java.io.File test=new java.io.File(testPath);
        final File absoluteFile=test.getAbsoluteFile();
        @SuppressWarnings("deprecation")
        final
        URL testURL=absoluteFile.toURL();

        wrapper.runExecuteOnlyTest(testPath, 0, 0, testURL.toString(), ps, System.err, args);

        final byte[] output = baos.toByteArray();
        final List<String> result = outputToStrings(output);

        final Double _result = filterBenchmark(result, benchmark);

        return _result;
    } catch (final Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
 
Example 3
Source File: WasStandaloneServer.java    From wasindoor with Apache License 2.0 6 votes vote down vote up
public static URLClassLoader getCalcClassLoader() {
	if (calcLoader == null) {
		File cl = new File(Configuration.calc_indoor_libdir);// ��Jar��
		URL indoor = null;

		try {
			indoor = cl.toURL();
		} catch (Exception e) {
			e.printStackTrace();
		}
		calcLoader = (new URLClassLoader(new URL[] { indoor }, Thread
				.currentThread().getContextClassLoader()));
	}

	return calcLoader;
}
 
Example 4
Source File: OctaneTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Double genericNashornTest(final String benchmark, final String testPath, final String[] args) throws Throwable {
    try {
        final PerformanceWrapper wrapper = new PerformanceWrapper();

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final PrintStream ps = new PrintStream(baos);

        final java.io.File test=new java.io.File(testPath);
        final File absoluteFile=test.getAbsoluteFile();
        @SuppressWarnings("deprecation")
        final
        URL testURL=absoluteFile.toURL();

        wrapper.runExecuteOnlyTest(testPath, 0, 0, testURL.toString(), ps, System.err, args);

        final byte[] output = baos.toByteArray();
        final List<String> result = outputToStrings(output);

        final Double _result = filterBenchmark(result, benchmark);

        return _result;
    } catch (final Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
 
Example 5
Source File: JdiLoadedByCustomLoader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create files from given arguments and tools.jar
    File f1 = new File(args[0]);
    String home = System.getProperty("java.home");
    String tools = ".." + File.separatorChar + "lib" +
        File.separatorChar + "tools.jar";
    File f2 = (new File(home, tools)).getCanonicalFile();

    // create class loader
    URL[] urls = { f1.toURL(), f2.toURL() };
    URLClassLoader cl = new URLClassLoader(urls);

    // load ListConnectors using the class loader
    // and then invoke the list method.
    Class c = Class.forName("ListConnectors", true, cl);
    Method m = c.getDeclaredMethod("list");
    Object o = c.newInstance();
    m.invoke(o);
}
 
Example 6
Source File: JdiLoadedByCustomLoader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create files from given arguments and tools.jar
    File f1 = new File(args[0]);
    String home = System.getProperty("java.home");
    String tools = ".." + File.separatorChar + "lib" +
        File.separatorChar + "tools.jar";
    File f2 = (new File(home, tools)).getCanonicalFile();

    // create class loader
    URL[] urls = { f1.toURL(), f2.toURL() };
    URLClassLoader cl = new URLClassLoader(urls);

    // load ListConnectors using the class loader
    // and then invoke the list method.
    Class c = Class.forName("ListConnectors", true, cl);
    Method m = c.getDeclaredMethod("list");
    Object o = c.newInstance();
    m.invoke(o);
}
 
Example 7
Source File: JdiLoadedByCustomLoader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create files from given arguments and tools.jar
    File f1 = new File(args[0]);
    String home = System.getProperty("java.home");
    String tools = ".." + File.separatorChar + "lib" +
        File.separatorChar + "tools.jar";
    File f2 = (new File(home, tools)).getCanonicalFile();

    // create class loader
    URL[] urls = { f1.toURL(), f2.toURL() };
    URLClassLoader cl = new URLClassLoader(urls);

    // load ListConnectors using the class loader
    // and then invoke the list method.
    Class c = Class.forName("ListConnectors", true, cl);
    Method m = c.getDeclaredMethod("list");
    Object o = c.newInstance();
    m.invoke(o);
}
 
Example 8
Source File: ToURL.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 9
Source File: Options.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds the <tt>META-INF/sun-jaxb.episode</tt> file to add as a binding customization.
 */
public void scanEpisodeFile(File jar) throws BadCommandLineException {
    try {
        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();
            addBindFile(new InputSource(url.toExternalForm()));
        }
    } catch (IOException e) {
        throw new BadCommandLineException(
                Messages.format(Messages.FAILED_TO_LOAD,jar,e.getMessage()), e);
    }
}
 
Example 10
Source File: ToURL.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 11
Source File: ClasspathUtilsTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void testGetClasspathComponentsDontHaveDuplicates() throws MalformedURLException
{
    String classpath = System.getProperty("java.class.path");
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try
    {
        String pathSep = System.getProperty("path.separator");
        File file = new File("/some/package/dir");
        URL[] urls = new URL[] { file.toURL() };            
        // assert my package can't be found yet
        List components = ClasspathUtils.getClasspathComponents();
        Collections.sort(components);
        assertTrue(Collections.binarySearch(components, file.getPath()) < 0);
        // test my package is found and only appears once
        URLClassLoader parentClassLoader = new URLClassLoader(urls, classLoader);
        URLClassLoader childClassLoader = new URLClassLoader(new URL[] {}, parentClassLoader);
        Thread.currentThread().setContextClassLoader(childClassLoader);
        System.setProperty("java.class.path", classpath + pathSep + file.getPath());
        components = ClasspathUtils.getClasspathComponents();
        Collections.sort(components);
        assertTrue(Collections.binarySearch(components, file.getPath()) >= 0);
        assertTrue(frequency(components, file.getPath()) == 1);
    }
    finally
    {
        Thread.currentThread().setContextClassLoader(classLoader);
        System.setProperty("java.class.path", classpath);
    }
    
}
 
Example 12
Source File: ToURL.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 13
Source File: UnloadClassBeanInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The Stub class is compiled by jtreg, but we want to move it so it is not
 * on the application classpath. We want to load it through a separate
 * classloader.
 */
static Class<?> getStub() throws Exception {
    final String testclasses = System.getProperty("test.classes");
    final File subdir = new File(testclasses, "stub");
    subdir.mkdir();

    final Path src = Paths.get(testclasses, "Stub.class");
    final Path dest = subdir.toPath().resolve("Stub.class");
    Files.move(src, dest, StandardCopyOption.REPLACE_EXISTING);

    loader = new URLClassLoader(new URL[]{subdir.toURL()});
    return Class.forName("Stub", true, loader);
}
 
Example 14
Source File: ToURL.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 15
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public URL apply(File from) {
	try {
		return from.toURL();
	} catch (MalformedURLException e) {
		throw new RuntimeException(e);
	}
}
 
Example 16
Source File: ToURL.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 17
Source File: AudioPreview.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public void preview(File file) {
   try {
     if(loader != null)
loader.stopClip();
     name = file.getName();
     setStatus("Loading " + name + "...");
     loader = new Loader(file.toURL());
   } catch(MalformedURLException e) {
     Util.printStackTrace(e);
   }    
 }
 
Example 18
Source File: ToURL.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 19
Source File: ToURL.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void go(String fn) throws Exception {
    File f = new File(fn);
    URL u = f.toURL();
    String ufn = u.getFile();
    if (!ufn.endsWith("/"))
        throw new Exception(u + " does not end with slash");
    if (ufn.endsWith("//"))
        throw new Exception(u + " ends with two slashes");
}
 
Example 20
Source File: STLFileReader.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Creates a <code>STLFileReader</code> object to read a STL file from a
 * file. The data may be in ASCII or binary format. A progress monitor will
 * show the progress during reading.
 * @param file <code>File</code> object of STL file to read.
 * @param parentComponent Parent <code>Component</code> of progress monitor.
 *      Use <code>null</code> if there is no parent.
 * @throws IllegalArgumentException The file was structurally incorrect
 */
public STLFileReader(File file, Component parentComponent)
    throws IllegalArgumentException, IOException
{
    this(file.toURL(), parentComponent);
}