java.io.File#toURL ( )源码实例Demo

下面列出了java.io.File#toURL ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: JdiLoadedByCustomLoader.java
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);
}
 
源代码2 项目: openjdk-jdk9   文件: OctaneTest.java
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;
    }
}
 
源代码3 项目: wasindoor   文件: WasStandaloneServer.java
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;
}
 
源代码4 项目: openjdk-8   文件: JdiLoadedByCustomLoader.java
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);
}
 
源代码5 项目: jdk8u60   文件: JdiLoadedByCustomLoader.java
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);
}
 
源代码6 项目: hottub   文件: JdiLoadedByCustomLoader.java
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);
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: OctaneTest.java
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;
    }
}
 
源代码8 项目: openjdk-8   文件: ToURL.java
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");
}
 
源代码9 项目: openjdk-jdk9   文件: ToURL.java
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");
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: ToURL.java
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");
}
 
源代码11 项目: pdfxtk   文件: AudioPreview.java
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);
   }    
 }
 
源代码12 项目: jdk8u-dev-jdk   文件: ToURL.java
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");
}
 
源代码13 项目: xtext-xtend   文件: XtendBatchCompiler.java
@SuppressWarnings("deprecation")
@Override
public URL apply(File from) {
	try {
		return from.toURL();
	} catch (MalformedURLException e) {
		throw new RuntimeException(e);
	}
}
 
源代码14 项目: jdk8u60   文件: ToURL.java
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");
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: UnloadClassBeanInfo.java
/**
 * 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);
}
 
源代码16 项目: jdk8u-jdk   文件: ToURL.java
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");
}
 
源代码17 项目: lams   文件: ClasspathUtilsTest.java
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);
    }
    
}
 
源代码18 项目: openjdk-jdk8u   文件: ToURL.java
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");
}
 
源代码19 项目: openjdk-8   文件: Options.java
/**
 * 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);
    }
}
 
源代码20 项目: android-3D-model-viewer   文件: STLFileReader.java
/**
 * 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);
}