当前位置: 首页>>代码示例>>Java>>正文


Java URLStreamHandlerFactory类代码示例

本文整理汇总了Java中java.net.URLStreamHandlerFactory的典型用法代码示例。如果您正苦于以下问题:Java URLStreamHandlerFactory类的具体用法?Java URLStreamHandlerFactory怎么用?Java URLStreamHandlerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


URLStreamHandlerFactory类属于java.net包,在下文中一共展示了URLStreamHandlerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createURLStreamHandler

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Creates a new URLStreamHandler instance with the specified protocol.
 * Will return null if the protocol is not <code>jndi</code>.
 * 
 * @param protocol the protocol (must be "jndi" here)
 * @return a URLStreamHandler for the jndi protocol, or null if the 
 * protocol is not JNDI
 */
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
    if (protocol.equals("jndi")) {
        return new DirContextURLStreamHandler();
    } else if (protocol.equals("classpath")) {
        return new ClasspathURLStreamHandler();
    } else {
        for (URLStreamHandlerFactory factory : userFactories) {
            URLStreamHandler handler =
                factory.createURLStreamHandler(protocol);
            if (handler != null) {
                return handler;
            }
        }
        return null;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:DirContextURLStreamHandlerFactory.java

示例2: createURL

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Creates a URL from the specified protocol name, host name, port number,
 * and file name.
 * <p/>
 * No validation of the inputs is performed by this method.
 *
 * @param protocol the name of the protocol to use
 * @param host     the name of the host
 * @param port     the port number
 * @param file     the file on the host
 * @return URL created using specified protocol, host, and file
 * @throws MalformedURLException if an unknown protocol is specified
 */
public static URL createURL(String protocol,
                            String host,
                            int port,
                            String file) throws MalformedURLException {
    URLStreamHandlerFactory factory = _factories.get(protocol);

    // If there is no URLStreamHandlerFactory registered for the
    // scheme/protocol, then we just use the regular URL constructor.
    if (factory == null) {
        return new URL(protocol, host, port, file);
    }

    // If there is a URLStreamHandlerFactory associated for the
    // scheme/protocol, then we create a URLStreamHandler. And, then use
    // then use the URLStreamHandler to create a URL.
    URLStreamHandler handler = factory.createURLStreamHandler(protocol);
    return new URL(protocol, host, port, file, handler);
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:32,代码来源:URLFactory.java

示例3: convert

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Convert an array of String to an array of URL and return it.
 *
 * @param input The array of String to be converted
 * @param factory Handler factory to use to generate the URLs
 */
protected static URL[] convert(String input[],
                               URLStreamHandlerFactory factory) {

    URLStreamHandler streamHandler = null;

    URL url[] = new URL[input.length];
    for (int i = 0; i < url.length; i++) {
        try {
            String protocol = parseProtocol(input[i]);
            if (factory != null)
                streamHandler = factory.createURLStreamHandler(protocol);
            else
                streamHandler = null;
            url[i] = new URL(null, input[i], streamHandler);
        } catch (MalformedURLException e) {
            url[i] = null;
        }
    }
    return (url);

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:28,代码来源:StandardClassLoader.java

示例4: URLClassPath

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Creates a new URLClassPath for the given URLs. The URLs will be
 * searched in the order specified for classes and resources. A URL
 * ending with a '/' is assumed to refer to a directory. Otherwise,
 * the URL is assumed to refer to a JAR file.
 *
 * @param urls the directory and JAR file URLs to search for classes
 *        and resources
 * @param factory the URLStreamHandlerFactory to use when creating new URLs
 * @param acc the context to be used when loading classes and resources, may
 *            be null
 */
public URLClassPath(URL[] urls,
                    URLStreamHandlerFactory factory,
                    AccessControlContext acc) {
    for (int i = 0; i < urls.length; i++) {
        path.add(urls[i]);
    }
    push(urls);
    if (factory != null) {
        jarHandler = factory.createURLStreamHandler("jar");
    }
    if (DISABLE_ACC_CHECKING)
        this.acc = null;
    else
        this.acc = acc;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:URLClassPath.java

示例5: URLClassPath

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Creates a new URLClassPath for the given URLs. The URLs will be
 * searched in the order specified for classes and resources. A URL
 * ending with a '/' is assumed to refer to a directory. Otherwise,
 * the URL is assumed to refer to a JAR file.
 *
 * @param urls the directory and JAR file URLs to search for classes
 *        and resources
 * @param factory the URLStreamHandlerFactory to use when creating new URLs
 * @param acc the context to be used when loading classes and resources, may
 *            be null
 */
public URLClassPath(URL[] urls,
                    URLStreamHandlerFactory factory,
                    AccessControlContext acc) {
    List<URL> path = new ArrayList<>(urls.length);
    for (URL url : urls) {
        path.add(url);
    }
    this.path = path;
    push(urls);
    if (factory != null) {
        jarHandler = factory.createURLStreamHandler("jar");
    } else {
        jarHandler = null;
    }
    if (DISABLE_ACC_CHECKING)
        this.acc = null;
    else
        this.acc = acc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:URLClassPath.java

示例6: installGitProtocol

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Installs the GIT protocol that we use to identify certain file versions.
 */
protected void installGitProtocol() {
  // Install protocol.
  try {
  URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
    @Override
    public URLStreamHandler createURLStreamHandler(String protocol) {
      if (protocol.equals(GitRevisionURLHandler.GIT_PROTOCOL)) {
        URLStreamHandler handler = new GitRevisionURLHandler();
        return handler;
      }
      
      return null;
    }
  });
  } catch (Throwable t) {
    if (!t.getMessage().contains("factory already defined")) {
      logger.info(t, t);
    }
  } 
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:24,代码来源:GitTestBase.java

示例7: createURLStreamHandler

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Creates a new URLStreamHandler instance with the specified protocol. Will
 * return null if the protocol is not <code>jndi</code>.
 * 
 * @param protocol
 *            the protocol (must be "jndi" here)
 * @return a URLStreamHandler for the jndi protocol, or null if the protocol
 *         is not JNDI
 */
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
	if (protocol.equals("jndi")) {
		return new DirContextURLStreamHandler();
	} else if (protocol.equals("classpath")) {
		return new ClasspathURLStreamHandler();
	} else {
		for (URLStreamHandlerFactory factory : userFactories) {
			URLStreamHandler handler = factory.createURLStreamHandler(protocol);
			if (handler != null) {
				return handler;
			}
		}
		return null;
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:26,代码来源:DirContextURLStreamHandlerFactory.java

示例8: createURL

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Tries to parse a <code>String</code> as an URL.
 * 
 * @param spec the <code>String</code> to parse
 * @param urlHandlerFactory an URL stream handler factory to use
 * @return an URL if the parsing is successful
 * @see #getURLHandler(String, URLStreamHandlerFactory)
 * @see #getURLHandlerFactory(URLStreamHandlerFactory)
 */
public static URL createURL(String spec, URLStreamHandlerFactory urlHandlerFactory)
{
	URLStreamHandler handler = getURLHandler(spec, urlHandlerFactory);
	URL url;
	try
	{
		if (handler == null)
		{
			url = new URL(spec);
		}
		else
		{
			url = new URL(null, spec, handler);
		}
	}
	catch (MalformedURLException e)
	{
		url = null;
	}
	return url;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:31,代码来源:JRResourcesUtil.java

示例9: getURLHandler

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Returns an URL stream handler for an URL specified as a <code>String</code>.
 * 
 * @param spec the <code>String</code> to parse as an URL
 * @param urlHandlerFact an URL stream handler factory
 * @return an URL stream handler if one was found for the protocol of the URL
 * @see #getURLHandlerFactory(URLStreamHandlerFactory)
 */
public static URLStreamHandler getURLHandler(String spec, URLStreamHandlerFactory urlHandlerFact)
{
	URLStreamHandlerFactory urlHandlerFactory = urlHandlerFact;//getURLHandlerFactory(urlHandlerFact);

	URLStreamHandler handler = null;
	if (urlHandlerFactory != null)
	{
		String protocol = getURLProtocol(spec);
		if (protocol != null)
		{
			handler = urlHandlerFactory.createURLStreamHandler(protocol);
		}
	}
	return handler;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:24,代码来源:JRResourcesUtil.java

示例10: JarURLLoader

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
private JarURLLoader(URLClassLoader classloader, URLStreamHandlerCache cache,
                     URLStreamHandlerFactory factory,
                     URL baseURL, URL absoluteUrl,
                     Set indexSet)
{
  super(classloader, cache, factory, baseURL, absoluteUrl);

  URL newBaseURL = null;
  try
    {
      // Cache url prefix for all resources in this jar url.
      String base = baseURL.toExternalForm() + "!/";
      newBaseURL = new URL("jar", "", -1, base, cache.get(factory, "jar"));
    }
  catch (MalformedURLException ignore)
    {
      // Ignore.
    }
  this.baseJarURL = newBaseURL;
  this.classPath = null;
  this.indexSet = indexSet;
}
 
开发者ID:vilie,项目名称:javify,代码行数:23,代码来源:JarURLLoader.java

示例11: get

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
public synchronized URLStreamHandler get(URLStreamHandlerFactory factory,
                                         String protocol)
{
  if (factory == null)
    return null;
  // Check if there're handler for the same protocol in cache.
  HashMap<String, URLStreamHandler> cache = factoryCache.get(factory);
  URLStreamHandler handler = cache.get(protocol);
  if (handler == null)
    {
      // Add it to cache.
      handler = factory.createURLStreamHandler(protocol);
      cache.put(protocol, handler);
    }
  return handler;
}
 
开发者ID:vilie,项目名称:javify,代码行数:17,代码来源:URLStreamHandlerCache.java

示例12: setupPizzaURLLoader

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
public static void setupPizzaURLLoader() {
    if (!customUrlLoader) {
        URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
            @Override
            public URLStreamHandler createURLStreamHandler(String protocol) {
                if (protocol.equals("pizza")) {
                    return new PizzaUrlHandler();
                } else {
                    return null;
                }
            }
        });

        customUrlLoader = true;
    }
}
 
开发者ID:loadtestgo,项目名称:pizzascript,代码行数:17,代码来源:ViewResultsPanel.java

示例13: setup

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
/**
 * Convenience method to set up the necessary HttpClient protocol and URL handler.
 *
 * Only works for HttpClient, because it's not possible (or at least very difficult)
 * to provide a different socket factory for the HttpURLConnection class.
 */
public static void setup(){
    final String LOOPBACK = "loopback"; // $NON-NLS-1$

    // This ensures tha HttpClient knows about the protocol
    Protocol.registerProtocol(LOOPBACK, new Protocol(LOOPBACK,new LoopbackHttpClientSocketFactory(),1));

    // Now allow the URL handling to work.
    URLStreamHandlerFactory ushf = new URLStreamHandlerFactory(){
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            if (protocol.equalsIgnoreCase(LOOPBACK)){
                return new URLStreamHandler(){
                    @Override
                    protected URLConnection openConnection(URL u) throws IOException {
                        return null;// not needed for HttpClient
                    }
                };
            }
            return null;
        }
    };

    java.net.URL.setURLStreamHandlerFactory(ushf);
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:31,代码来源:LoopbackHttpClientSocketFactory.java

示例14: loadUrlStreamHandlerFactory

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
static URLStreamHandlerFactory loadUrlStreamHandlerFactory(String protocol) {
    String artifact = System.getProperty(protocol+"MvnUrlHandler",String.format(HANDLER_FACTORT_ARTIFACT,protocol));

    Collection<URLStreamHandlerFactory> urlStreamHandlerFactories = MavenServiceLoader.loadServices(
            artifact, URLStreamHandlerFactory.class);

    if(urlStreamHandlerFactories.isEmpty()){
        return null;
    } else if(urlStreamHandlerFactories.size() == 1){
        return urlStreamHandlerFactories.iterator().next();
    } else {
        URLStreamHandlerFactory[] streamHandlerFactories = urlStreamHandlerFactories.toArray(
                new URLStreamHandlerFactory[urlStreamHandlerFactories.size()]);
        return new ChainURLStreamHandlerFactory(streamHandlerFactories);
    }
}
 
开发者ID:igor-suhorukov,项目名称:mvn-classloader,代码行数:17,代码来源:LoadableURLStreamHandlerFactory.java

示例15: main

import java.net.URLStreamHandlerFactory; //导入依赖的package包/类
public static void main(String args[]) {

		// Unlock Security Management
		System.setSecurityManager(new UnsafeSecurityManager());

		// Set URL Stream Handler for jeditresource (hack/fix for jEdit Web
		// Start)
		try {
			URLStreamHandlerFactory factory;
			factory = new JEditURLStreamHandlerFactory();

			if (factory != null) {
				URL.setURLStreamHandlerFactory(factory);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		
		// Loader Window
		LoaderJFrame loader = new LoaderJFrame();
		loader.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//loader.autoload();
	}
 
开发者ID:AbnerLin,项目名称:PLWeb-Destop-Version,代码行数:25,代码来源:RunEditor.java


注:本文中的java.net.URLStreamHandlerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。