URLStreamHandlerFactory myFactory = new MyCustomStreamHandlerFactory(); URL.setURLStreamHandlerFactory(myFactory);
setURLStreamHandlerFactory method can only be called once for a Java Virtual Machine
While this may be adequate for standalone
applications this can be a problem where multiple applications run
within the same JVM, such as in a web application environment.
JNet uses a technique to circumvent this restriction and allow URL stream handler factories to be registered based on
the current execution context
, so it's possible to have different handlers for different applications running in
the same JVM. It also provides the facility to overcome the limitation of only being able to call the
provides the facility to set the
URLStreamHandlerFactory, even if already set by another application.
URLStreamHandlerFactory myFactory = new MyCustomStreamHandlerFactory(); Installer.setURLStreamHandlerFactory(myFactory);
URLStreamHandlerFactory has alreay been set AND
the new factory is a
then the old factory is set as the parent
provides the facility for different applications to use different
implementations by storing delegate
URLStreamHandlerFactory implementations in a
// At startup, set the DynamicURLStreamHandlerFactory URLStreamHandlerFactory dynamicFactory = new DynamicURLStreamHandlerFactory(); Installer.setURLStreamHandlerFactory(dynamicFactory); .... // Set a custom URLStreamHandlerFactory for the current context URLStreamHandlerFactory myFactory = new MyCustomStreamHandlerFactory(); DynamicURLStreamHandlerFactory.push(myFactory); ...