java.net.URLStreamHandlerFactory Java Examples
The following examples show how to use
java.net.URLStreamHandlerFactory.
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: URLClassPath.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #2
Source File: URLClassPath.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #3
Source File: JRResourcesUtil.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 */ 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; }
Example #4
Source File: URLFactory.java From particle-android with Apache License 2.0 | 6 votes |
/** * 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); }
Example #5
Source File: DirContextURLStreamHandlerFactory.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * 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; } }
Example #6
Source File: TomcatURLStreamHandlerFactory.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Release references to any user provided factories that have been loaded * using the provided class loader. Called during web application stop to * prevent memory leaks. * * @param classLoader The class loader to release */ public static void release(ClassLoader classLoader) { if (instance == null) { return; } List<URLStreamHandlerFactory> factories = instance.userFactories; for (URLStreamHandlerFactory factory : factories) { ClassLoader factoryLoader = factory.getClass().getClassLoader(); while (factoryLoader != null) { if (classLoader.equals(factoryLoader)) { // Implementation note: userFactories is a // CopyOnWriteArrayList, so items are removed with // List.remove() instead of usual Iterator.remove() factories.remove(factory); break; } factoryLoader = factoryLoader.getParent(); } } }
Example #7
Source File: URLClassPath.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #8
Source File: URLClassPath.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #9
Source File: URLClassPath.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #10
Source File: URLClassPath.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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) { ArrayList<URL> path = new ArrayList<>(urls.length); ArrayDeque<URL> unopenedUrls = new ArrayDeque<>(urls.length); for (URL url : urls) { path.add(url); unopenedUrls.add(url); } this.path = path; this.unopenedUrls = unopenedUrls; if (factory != null) { jarHandler = factory.createURLStreamHandler("jar"); } else { jarHandler = null; } if (DISABLE_ACC_CHECKING) this.acc = null; else this.acc = acc; }
Example #11
Source File: JarRuntimeInfoTest.java From components with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupMavenUrlHandler() { try { new URL("mvn:foo/bar"); } catch (MalformedURLException e) { // handles mvn local repository String mvnLocalRepo = System.getProperty("maven.repo.local"); if (mvnLocalRepo != null) { System.setProperty("org.ops4j.pax.url.mvn.localRepository", mvnLocalRepo); } URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (ServiceConstants.PROTOCOL.equals(protocol)) { return new Handler(); } else { return null; } } }); } }
Example #12
Source File: URLClassPath.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #13
Source File: DirContextURLStreamHandlerFactory.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * 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; } }
Example #14
Source File: SimpleRuntimeInfoTest.java From components with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupMavenUrlHandler() { try { new URL("mvn:foo/bar"); } catch (MalformedURLException e) { // handles mvn local repository String mvnLocalRepo = System.getProperty("maven.repo.local"); if (mvnLocalRepo != null) { System.setProperty("org.ops4j.pax.url.mvn.localRepository", mvnLocalRepo); } URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (ServiceConstants.PROTOCOL.equals(protocol)) { return new Handler(); } else { return null; } } }); } }
Example #15
Source File: URLClassPath.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #16
Source File: TestTomcatURLStreamHandlerFactory.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testUserFactory() throws Exception { URLStreamHandlerFactory factory = new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { return null; } }; TomcatURLStreamHandlerFactory.getInstance().addUserFactory(factory); TomcatURLStreamHandlerFactory.release(factory.getClass().getClassLoader()); }
Example #17
Source File: StreamHandlerFactory.java From LoboBrowser with MIT License | 5 votes |
public URLStreamHandler createURLStreamHandler(final String protocol) { final Collection<URLStreamHandlerFactory> factories = this.factories; synchronized (factories) { for (final URLStreamHandlerFactory f : factories) { final URLStreamHandler handler = f.createURLStreamHandler(protocol); if (handler != null) { return handler; } } } return null; }
Example #18
Source File: Handler.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
/** * Sets the URL stream handler factory for the environment. This * allows specification of the factory used in creating underlying * stream handlers. This can be called once per JVM instance. * * @param factory * The URL stream handler factory. */ public static void setURLStreamHandlerFactory ( URLStreamHandlerFactory factory ) { synchronized ( PROTOCOL_HANDLERS ) { if ( Handler.factory != null ) { throw new IllegalStateException("URLStreamHandlerFactory already set."); } PROTOCOL_HANDLERS.clear(); Handler.factory = factory; } }
Example #19
Source File: Handler.java From jcifs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Sets the URL stream handler factory for the environment. This * allows specification of the factory used in creating underlying * stream handlers. This can be called once per JVM instance. * * @param factory The URL stream handler factory. */ public static void setURLStreamHandlerFactory( URLStreamHandlerFactory factory) { synchronized (PROTOCOL_HANDLERS) { if (Handler.factory != null) { throw new IllegalStateException( "URLStreamHandlerFactory already set."); } PROTOCOL_HANDLERS.clear(); Handler.factory = factory; } }
Example #20
Source File: JRAbstractExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ @SuppressWarnings("deprecation") protected void ensureJasperReportsContext() { if ( parameters.containsKey(JRExporterParameter.CLASS_LOADER) || parameters.containsKey(JRExporterParameter.URL_HANDLER_FACTORY) ) { net.sf.jasperreports.engine.util.LocalJasperReportsContext localJasperReportsContext = new net.sf.jasperreports.engine.util.LocalJasperReportsContext(jasperReportsContext); if (parameters.containsKey(JRExporterParameter.CLASS_LOADER)) { localJasperReportsContext.setClassLoader((ClassLoader)parameters.get(JRExporterParameter.CLASS_LOADER)); } if (parameters.containsKey(JRExporterParameter.URL_HANDLER_FACTORY)) { localJasperReportsContext.setURLStreamHandlerFactory((URLStreamHandlerFactory)parameters.get(JRExporterParameter.URL_HANDLER_FACTORY)); } setJasperReportsContext(localJasperReportsContext); } FontUtil.getInstance(jasperReportsContext).resetThreadMissingFontsCache(); }
Example #21
Source File: HttpFunctionsTest.java From agera with Apache License 2.0 | 5 votes |
@BeforeClass public static void onlyOnce() throws Throwable { mockHttpURLConnection = mock(HttpURLConnection.class); URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(final String s) { return s.equals(TEST_PROTOCOL) ? new URLStreamHandler() { @Override protected URLConnection openConnection(final URL url) throws IOException { return mockHttpURLConnection; } } : null; } }); }
Example #22
Source File: Handler.java From jcifs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Sets the URL stream handler factory for the environment. This * allows specification of the factory used in creating underlying * stream handlers. This can be called once per JVM instance. * * @param factory * The URL stream handler factory. */ public static void setURLStreamHandlerFactory ( URLStreamHandlerFactory factory ) { synchronized ( PROTOCOL_HANDLERS ) { if ( Handler.factory != null ) { throw new IllegalStateException("URLStreamHandlerFactory already set."); } PROTOCOL_HANDLERS.clear(); Handler.factory = factory; } }
Example #23
Source File: ProxyURLStreamHandlerFactory.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void resultChanged(LookupEvent ev) { Collection<? extends URLStreamHandlerFactory> c = r.allInstances(); synchronized (this) { handlers = c.toArray(new URLStreamHandlerFactory[c.size()]); } }
Example #24
Source File: ImportsResolverImplTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@BeforeClass public static void setupURLStreamHandlerFactory() { // Allows for mocking URL connections URLStreamHandlerFactory urlStreamHandlerFactory = mock(URLStreamHandlerFactory.class); URL.setURLStreamHandlerFactory(urlStreamHandlerFactory); httpUrlStreamHandler = new HttpUrlStreamHandler(); when(urlStreamHandlerFactory.createURLStreamHandler("http")).thenReturn(httpUrlStreamHandler); when(urlStreamHandlerFactory.createURLStreamHandler("https")).thenReturn(httpUrlStreamHandler); }
Example #25
Source File: StreamHandlerFactory.java From LoboBrowser with MIT License | 5 votes |
public void addFactory(final URLStreamHandlerFactory factory) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkSetFactory(); } final Collection<URLStreamHandlerFactory> factories = this.factories; synchronized (factories) { factories.add(factory); } }
Example #26
Source File: ProxyURLStreamHandlerFactory.java From netbeans with Apache License 2.0 | 4 votes |
private ProxyURLStreamHandlerFactory(URLStreamHandlerFactory delegate) { this.delegate = delegate; LOG.log(Level.FINE, "new ProxyURLStreamHandlerFactory. delegate={0} originalJarHandler={1}", new Object[]{delegate, originalJarHandler}); }
Example #27
Source File: LocalJasperReportsContext.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ public void setURLStreamHandlerFactory(URLStreamHandlerFactory urlHandlerFactory) { getLocalRepositoryService().setURLStreamHandlerFactory(urlHandlerFactory); }
Example #28
Source File: JRResourcesFillUtil.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * @deprecated To be removed. */ public void setUrlHandlerFactory(URLStreamHandlerFactory urlHandlerFactory) { this.urlHandlerFactory = urlHandlerFactory; }
Example #29
Source File: Extension.java From LoboBrowser with MIT License | 4 votes |
public void addURLStreamHandlerFactory(final URLStreamHandlerFactory factory) { // TODO: Since extensions are intialized in parallel, // this is not necessarily done in order of priority. StreamHandlerFactory.getInstance().addFactory(factory); }
Example #30
Source File: RequestReplyNoAdvisoryNetworkTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void testNonAdvisoryNetworkRequestReplyXmlConfig() throws Exception { final String xmlConfigString = new String("<beans" + " xmlns=\"http://www.springframework.org/schema/beans\"" + " xmlns:amq=\"http://activemq.apache.org/schema/core\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans" + " http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" + " http://activemq.apache.org/schema/core" + " http://activemq.apache.org/schema/core/activemq-core.xsd\">" + " <broker xmlns=\"http://activemq.apache.org/schema/core\" id=\"broker\"" + " allowTempAutoCreationOnSend=\"true\" schedulePeriodForDestinationPurge=\"1000\"" + " brokerName=\"%HOST%\" persistent=\"false\" advisorySupport=\"false\" useJmx=\"false\" >" + " <destinationPolicy>" + " <policyMap>" + " <policyEntries>" + " <policyEntry optimizedDispatch=\"true\" gcInactiveDestinations=\"true\" gcWithNetworkConsumers=\"true\" inactiveTimoutBeforeGC=\"1000\">" + " <destination>" + " <tempQueue physicalName=\"" + replyQWildcard.getPhysicalName() + "\"/>" + " </destination>" + " </policyEntry>" + " </policyEntries>" + " </policyMap>" + " </destinationPolicy>" + " <networkConnectors>" + " <networkConnector uri=\"multicast://default\">" + " <staticallyIncludedDestinations>" + " <queue physicalName=\"" + sendQ.getPhysicalName() + "\"/>" + " <tempQueue physicalName=\"" + replyQWildcard.getPhysicalName() + "\"/>" + " </staticallyIncludedDestinations>" + " </networkConnector>" + " </networkConnectors>" + " <transportConnectors>" + " <transportConnector uri=\"tcp://0.0.0.0:0\" discoveryUri=\"multicast://default\" />" + " </transportConnectors>" + " </broker>" + "</beans>"); final String localProtocolScheme = "inline"; URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (localProtocolScheme.equalsIgnoreCase(protocol)) { return new URLStreamHandler() { @Override protected URLConnection openConnection(URL u) throws IOException { return new URLConnection(u) { @Override public void connect() throws IOException { } @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(xmlConfigString.replace("%HOST%", url.getFile()).getBytes(StandardCharsets.UTF_8)); } }; } }; } return null; } }); a = new XBeanBrokerFactory().createBroker(new URI("xbean:" + localProtocolScheme + ":A")); b = new XBeanBrokerFactory().createBroker(new URI("xbean:" + localProtocolScheme + ":B")); brokers.add(a); brokers.add(b); doTestNonAdvisoryNetworkRequestReply(); }