URL.setURLStreamHandlerFactory(new CustomURLStreamHandlerFactory());
@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; } }); }
URL.setURLStreamHandlerFactory( (URLStreamHandlerFactory) Class.forName( "org.fourthline.cling.transport.impl.FixedSunURLStreamHandler"
URL.setURLStreamHandlerFactory(new WarUrlStreamHandlerFactory());
@Override public void evaluate() throws Throwable { Field factoryField = null; int matches = 0; URLStreamHandlerFactory oldFactory = null; for (final Field field : URL.class.getDeclaredFields()) { if (URLStreamHandlerFactory.class.equals(field.getType())) { factoryField = field; matches++; factoryField.setAccessible(true); oldFactory = (URLStreamHandlerFactory) factoryField.get(null); break; } } Assert.assertNotNull("java.net URL does not declare a java.net.URLStreamHandlerFactory field", factoryField); Assert.assertEquals("java.net.URL declares multiple java.net.URLStreamHandlerFactory fields.", 1, matches); // FIXME There is a break in the loop so always 0 or 1 URL.setURLStreamHandlerFactory(newURLStreamHandlerFactory); try { base.evaluate(); } finally { clearURLHandlers(); factoryField.set(null, null); URL.setURLStreamHandlerFactory(oldFactory); } } };
/** * Install an instance of this class as UrlStreamHandlerFactory. This may be done exactly once as {@link URL} will throw an * {@link Error} on subsequent invocations. * <p> * This method takes care that multiple invocations are possible, but the UrlStreamHandlerFactory is installed only once. */ public static synchronized void installUrlStreamHandlerFactory() { /* * When running under surefire, this class will be loaded by different class loaders and will be running in multiple "main" * thread objects. Thus, there is no way for this class to register a globally available variable to store the info whether * our custom UrlStreamHandlerFactory was already registered. * * The only way to accomplish this is to catch the Error that is thrown by URL when trying to re-register the custom * UrlStreamHandlerFactory. */ try { URL.setURLStreamHandlerFactory(new MuleUrlStreamHandlerFactory()); } catch (Error err) { if (log.isDebugEnabled()) { log.debug("Custom MuleUrlStreamHandlerFactory already registered", err); } } }
/** * Starts a forked server process using the standard input and output * streams for communication with the parent process. Any attempts by * stray code to read from standard input or write to standard output * is redirected to avoid interfering with the communication channel. * * @param args command line arguments, ignored * @throws Exception if the server could not be started */ public static void main(String[] args) throws Exception { long serverPulseMillis = Long.parseLong(args[0]); long serverParseTimeoutMillis = Long.parseLong(args[1]); long serverWaitTimeoutMillis = Long.parseLong(args[2]); URL.setURLStreamHandlerFactory(new MemoryURLStreamHandlerFactory()); ForkServer server = new ForkServer(System.in, System.out, serverPulseMillis, serverParseTimeoutMillis, serverWaitTimeoutMillis); System.setIn(new ByteArrayInputStream(new byte[0])); System.setOut(System.err); Thread watchdog = new Thread(server, "Tika Watchdog"); watchdog.setDaemon(true); watchdog.start(); server.processRequests(); }
URL.setURLStreamHandlerFactory( (URLStreamHandlerFactory) Class.forName( "org.fourthline.cling.transport.impl.FixedSunURLStreamHandler"
private TomcatURLStreamHandlerFactory(boolean register) { // Hide default constructor // Singleton pattern to ensure there is only one instance of this // factory this.registered = register; if (register) { URL.setURLStreamHandlerFactory(this); } }
public synchronized void register() { if (!registered) { URL.setURLStreamHandlerFactory(this); registered = true; } }
/** * Reset any cached handlers just in case a jar protocol has already been used. We * reset the handler by trying to set a null {@link URLStreamHandlerFactory} which * should have no effect other than clearing the handlers cache. */ private static void resetCachedUrlHandlers() { try { URL.setURLStreamHandlerFactory(null); } catch (Error ex) { // Ignore } }
private TomcatURLStreamHandlerFactory(boolean register) { // Hide default constructor // Singleton pattern to ensure there is only one instance of this // factory this.registered = register; if (register) { URL.setURLStreamHandlerFactory(this); } }
/** * <p>initialize</p> * Initializing the URL Factory */ public static void initialize() { try { URL.setURLStreamHandlerFactory(genericUrlFactory); } catch (Error exception) { // ignore error concerning resetting the URLStreamHandlerFactory } }
/** * <p>initialize</p> * Initializing the URL Factory */ public static void initialize() { try { URL.setURLStreamHandlerFactory(genericUrlFactory); } catch (Error exception) { // ignore error concerning resetting the URLStreamHandlerFactory } }
public Void run() { URL.setURLStreamHandlerFactory(ushf); return null; } });
/** * Reset any cached handlers just in case a jar protocol has already been used. We * reset the handler by trying to set a null {@link URLStreamHandlerFactory} which * should have no effect other than clearing the handlers cache. */ private static void resetCachedUrlHandlers() { try { URL.setURLStreamHandlerFactory(null); } catch (Error ex) { // Ignore } }
public static String unsetURLStreamHandlerFactory() { try { Field f = URL.class.getDeclaredField("factory"); f.setAccessible(true); Object curFac = f.get(null); f.set(null, null); URL.setURLStreamHandlerFactory(null); return curFac.getClass().getName(); } catch (Exception e) { return null; } }
public static void register() { if (!registered) { URL.setURLStreamHandlerFactory(new JarJarURLStreamHandlerFactory()); registered = true; } }
static public void install() { try { if (!installed) { java.net.URL.setURLStreamHandlerFactory( new URLStreamHandlerFactory() ); installed = true; } } catch (Error e) { log.error("Error installing URLStreamHandlerFactory "+e.getMessage()); // Log.errorG("Error installing URLStreamHandlerFactory "+e.getMessage()); } }
protected void initHdfs() { try { URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory()); } catch (Throwable e) { // ignore as its most likely already set LOG.debug("Cannot set URLStreamHandlerFactory due " + e.getMessage() + ". This exception will be ignored.", e); } }