public class ClasspathFontStreamProvider extends Object implements FontStreamProvider, com.levigo.jadice.fontmanager.internal.ProvidesCacheable
SeekableInputStream
on demand. It loads the
complete resource at creation time and uses the default cache to store the resource's bytes for
later access. If the cache lost the resource's bytes, they will be recreated on demand.
This is done because classpath resources seem to be unsafe in highly concurrent environments
accessing the same resource multiple times. In many cases the close()
-method was called
while another thread has just created an InputStream
for the same resource. We avoid this
by reading all bytes synchronously from a freshly created InputStream
and store them in
memory.
Modifier and Type | Field and Description |
---|---|
protected Object |
bytesCacheKey |
protected Object |
streamCacheKey |
Constructor and Description |
---|
ClasspathFontStreamProvider(String resourcePath)
Creates a new instance by loading and caching the requested classpath resource.
|
ClasspathFontStreamProvider(String resourcePath,
Class<?> loader)
Creates a new instance by loading and caching the requested classpath resource.
|
Modifier and Type | Method and Description |
---|---|
SeekableInputStream |
get()
Provides an instance of
T . |
Object |
getCacheKey() |
Class<?> |
getLoader() |
String |
getResourcePath() |
String |
toString() |
protected final Object bytesCacheKey
protected final Object streamCacheKey
public ClasspathFontStreamProvider(String resourcePath, Class<?> loader) throws IOException
resourcePath
is used as part of the cache key.resourcePath
- The requested classpath resource's path loadable by the given loader
class. Must not be null
.loader
- The class, which is able to load the requested classpath resource. Must not be
null
.IOException
- If any of the I/O operations went wrong.IllegalArgumentException
- resourcePath
or loader
,
was null
.resourcePath
was not found or could
not be loaded.public ClasspathFontStreamProvider(String resourcePath) throws IOException
resourcePath
is used as the cache key.resourcePath
- The requested classpath resource's path loadable via local class loader
hierarchy. Must not be null
.IOException
- If any of the I/O operations went wrong.IllegalArgumentException
- resourcePath
was null
.resourcePath
was not found or could
not be loaded.public SeekableInputStream get() throws IOException
Provider
T
. Must never return null
. Whether this method may be
called more that one time is not specified. Supporting multiple calls is up to the
implementation.get
in interface Provider<SeekableInputStream,IOException>
IOException
public Object getCacheKey()
getCacheKey
in interface com.levigo.jadice.fontmanager.internal.ProvidesCacheable
public String getResourcePath()
public Class<?> getLoader()
Copyright © 2024 levigo holding gmbh. All rights reserved.