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


Java URLStreamHandler类代码示例

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


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

示例1: literalURL

import java.net.URLStreamHandler; //导入依赖的package包/类
static URL literalURL(final String content) {
    try {
        return new URL("literal", null, 0, content, new URLStreamHandler() {
            @Override
            protected URLConnection openConnection(URL u) throws IOException {
                return new URLConnection(u) {
                    public @Override
                    InputStream getInputStream() throws IOException {
                        return new ByteArrayInputStream(content.getBytes());
                    }

                    public @Override
                    void connect() throws IOException {
                    }
                };
            }
        });
    } catch (MalformedURLException x) {
        throw new AssertionError(x);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:RepositoryIncludeTest.java

示例2: check

import java.net.URLStreamHandler; //导入依赖的package包/类
private void check(final String n) {
    assertNull(Lookups.metaInfServices(new ClassLoader() {
        protected @Override Enumeration<URL> findResources(String name) throws IOException {
            if (name.equals("META-INF/services/java.lang.Object")) {
                return singleton(new URL(null, "dummy:stuff", new URLStreamHandler() {
                    protected URLConnection openConnection(URL u) throws IOException {
                        return new URLConnection(u) {
                            public void connect() throws IOException {}
                            public @Override InputStream getInputStream() throws IOException {
                                return new ByteArrayInputStream(n.getBytes("UTF-8"));
                            }
                        };
                    }
                }));
            } else {
                return Collections.enumeration(Collections.<URL>emptyList());
            }
        }

    }).lookup(Object.class));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:MetaInfServicesLookupTest.java

示例3: createURLStreamHandler

import java.net.URLStreamHandler; //导入依赖的package包/类
public @Override synchronized URLStreamHandler createURLStreamHandler(final String protocol) {
    if (STANDARD_PROTOCOLS.contains(protocol)) {
        // Well-known handlers in JRE. Do not try to initialize lookup.
        return null;
    }
    if (!results.containsKey(protocol)) {
        final Lookup.Result<URLStreamHandler> result = Lookups.forPath("URLStreamHandler/" + protocol).lookupResult(URLStreamHandler.class);
        LookupListener listener = new LookupListener() {
            public @Override void resultChanged(LookupEvent ev) {
                synchronized (ProxyURLStreamHandlerFactory.this) {
                    Collection<? extends URLStreamHandler> instances = result.allInstances();
                    handlers.put(protocol, instances.isEmpty() ? null : instances.iterator().next());
                }
            }
        };
        result.addLookupListener(listener);
        listener.resultChanged(null);
        results.put(protocol, result);
    }
    return handlers.get(protocol);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ProxyURLStreamHandlerFactory.java

示例4: createURLStreamHandler

import java.net.URLStreamHandler; //导入依赖的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

示例5: load

import java.net.URLStreamHandler; //导入依赖的package包/类
/**
 * Creates a new URL object that retrieves the content specified by the
 * given URL with credentials. Internally the content is pre-fetched with
 * the given credentials. The returned URL has a custom protocol handler
 * that simply returns the pre-fetched content.
 * 
 * @param url
 *            the URL to read
 * @param username
 * @param password
 * @return an URL with a custom protocol handler
 * @throws IOException
 *             if an I/O exception occurs.
 */
public static URL load(final URL url, final String username,
        final String password) throws IOException {

    final byte[] content = getUrlContent(url, username, password);

    final URLStreamHandler handler = new URLStreamHandler() {

        @Override
        protected URLConnection openConnection(URL u) throws IOException {
            return new URLConnection(url) {
                @Override
                public void connect() throws IOException {
                }

                @Override
                public InputStream getInputStream() throws IOException {
                    return new ByteArrayInputStream(content);
                }
            };
        }
    };
    return new URL(url.getProtocol(), url.getHost(), url.getPort(), url
            .getFile(), handler);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:39,代码来源:BasicAuthLoader.java

示例6: buildUrl

import java.net.URLStreamHandler; //导入依赖的package包/类
private static URL buildUrl(String urlSpec,
                            URLStreamHandler handler) {
    try {
        URLStreamHandler keyHandler;
        if (handler == null && urlSpec.startsWith(LEP_PROTOCOL + ":")) {
            keyHandler = buildDefaultStreamHandler();
        } else {
            keyHandler = handler;
        }

        return new URL(null, urlSpec, keyHandler);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Can't build URL by LEP resource spec: "
                                               + urlSpec
                                               + " because of error: "
                                               + e.getMessage(), e);
    }
}
 
开发者ID:xm-online,项目名称:xm-lep,代码行数:19,代码来源:UrlLepResourceKey.java

示例7: createURL

import java.net.URLStreamHandler; //导入依赖的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

示例8: registerHandler

import java.net.URLStreamHandler; //导入依赖的package包/类
public static void registerHandler(final AssetManager manager) {
    URL.setURLStreamHandlerFactory(protocol -> "assets".equals(protocol) ? new URLStreamHandler() {
        protected URLConnection openConnection(URL url) throws IOException {
            return new URLConnection(url) {
                @Override
                public void connect() throws IOException {
                }

                @Override
                public InputStream getInputStream() throws IOException {
                    return manager.open(url.getFile());
                }
            };
        }
    } : null);
}
 
开发者ID:stariy95,项目名称:cayenne-android-demo,代码行数:17,代码来源:UrlToAssetUtils.java

示例9: addRepository

import java.net.URLStreamHandler; //导入依赖的package包/类
/**
 * Add a new repository to the set of places this ClassLoader can look for
 * classes to be loaded.
 *
 * @param repository Name of a source of classes to be loaded, such as a
 *  directory pathname, a JAR file pathname, or a ZIP file pathname
 *
 * @exception IllegalArgumentException if the specified repository is
 *  invalid or does not exist
 */
public void addRepository(String repository) {

    if (debug >= 1)
        log("addRepository(" + repository + ")");

    // Add this repository to our underlying class loader
    try {
        URLStreamHandler streamHandler = null;
        String protocol = parseProtocol(repository);
        if (factory != null)
            streamHandler = factory.createURLStreamHandler(protocol);
        URL url = new URL(null, repository, streamHandler);
        super.addURL(url);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e.toString());
    }

    // Add this repository to our internal list
    addRepositoryInternal(repository);

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

示例10: convert

import java.net.URLStreamHandler; //导入依赖的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

示例11: createParserFromUrl

import java.net.URLStreamHandler; //导入依赖的package包/类
@Test
public void createParserFromUrl() throws Exception {
    class NullUrlConnection extends URLConnection {
        protected NullUrlConnection(URL url) {
            super(url);
        }

        @Override
        public void connect() throws IOException {
        }

        @Override
        public InputStream getInputStream() {
            return new ByteArrayInputStream(new byte[0]);
        }
    };

    class NullUrlStreamHandler extends URLStreamHandler {
        @Override
        protected URLConnection openConnection(URL u) throws IOException {
            return new NullUrlConnection(u);
        }
    };

    assertThat(factory.createParser(new URL("foo", "bar", 99, "baz", new NullUrlStreamHandler())), instanceOf(IonParser.class));
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:27,代码来源:IonFactoryTest.java

示例12: testProvideServiceNotInModule

import java.net.URLStreamHandler; //导入依赖的package包/类
/**
 * Test redefineClass by attempting to update java.base to provide a service
 * where the service provider class is not in the module.
 */
@Test(expectedExceptions = IllegalArgumentException.class)
public void testProvideServiceNotInModule() {
    Module baseModule = Object.class.getModule();
    class MyProvider extends URLStreamHandlerProvider {
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            return null;
        }
    }

    // attempt to update java.base to provide MyProvider
    Map<Class<?>, List<Class<?>>> extraProvides
        = Map.of(URLStreamHandlerProvider.class, List.of(MyProvider.class));
    redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:RedefineModuleTest.java

示例13: createURLStreamHandler

import java.net.URLStreamHandler; //导入依赖的package包/类
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
	// don't do classloading when called for protocols that are involved in classloading
	if(protocol.equals("file") || protocol.equals("jar"))
		return null;
	String clsName = packageName + "." + protocol + ".Handler";
	try
	{
		Class cls = Class.forName(clsName);
		return (URLStreamHandler) cls.newInstance();
	} catch (Throwable e)
	{
		// URLs are involved in classloading, evil things might happen
	}
	return null;
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:17,代码来源:AzURLStreamHandlerFactory.java

示例14: installGitProtocol

import java.net.URLStreamHandler; //导入依赖的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

示例15: createURLStreamHandler

import java.net.URLStreamHandler; //导入依赖的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


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