public abstract class AbstractStreamLocator extends AbstractLocator
An abstract base class for Locator
implementations that mainly
operate on streams.
The Locator
interface requires that the getURL()
method has to be implemented in a meaningful way. However, there are some use
cases where data is available only as a stream (e.g. in some binary form),
and it is not obvious how a URL can be constructed to point to this data.
This class is designed to support such use cases.
The basic idea is that this class provides a specialized implementation of
the abstract java.net.URLStreamHandler
class. This
implementation can create java.net.URLConnection
objects whose
getInputStream()
method returns the input stream provided by the
concrete Locator
implementation.
Concrete subclasses have to implement the getInputStream()
method to return the stream they point to. They also have to provide an
implementation of the createURL()
method. This method is passed
a URLStreamHandler
object as described above. An implementation
of createURL()
can create a URL with an arbitrary protocol and
other components as it sees fit. As long as the URLStreamHandler
is used when creating the URL it is guaranteed that calls to
openConnection()
or openStream()
on the URL object
return the stream of the Locator
.
Modifier | Constructor and Description |
---|---|
protected |
AbstractStreamLocator()
Creates a new instance of
AbstractStreamLocator . |
Modifier and Type | Method and Description |
---|---|
protected abstract URL |
createURL(URLStreamHandler streamHandler)
Creates the URL managed by this locator.
|
URL |
getURL()
Returns the
URL managed by this locator. |
getFile, getInputStream
protected AbstractStreamLocator()
AbstractStreamLocator
.public URL getURL()
URL
managed by this locator. On first access
this implementation delegates to createURL()
for creating
the URL. Then the URL is cached and directly returned on subsequent
requests. Note that a non-blocking algorithm is used for lazily creating
the URL. So on concurrent access it may happen that
createURL()
is invoked multiple times. However, it is
guaranteed that this method always returns the same URL
.URL
managed by this locatorprotected abstract URL createURL(URLStreamHandler streamHandler) throws MalformedURLException
getURL()
to initialize the URL. An implementation is free to
create whatever URL it likes, but it should use the specified
URLStreamHandler
. This handler ensures that reading from the
URL is delegated to the stream managed by this locator.streamHandler
- the stream handler to use when creating the URLgetURL()
MalformedURLException
- if the URL cannot be createdCopyright © 2016 The JGUIraffe Team. All rights reserved.