public class FileFontAttributesCache extends Object implements FontAttributesCache<String,FileNotFoundException>
FontAttributesCache
which keeps the contents of the cache in
a file. The cache will be read during the creationg of the FileFontAttributesCache
object
and kept in the memory afterwards. To persist the changes made to the cache the
writeCache()
method has to be called.Constructor and Description |
---|
FileFontAttributesCache(File cacheFile)
Creates a new
FileFontAttributesCache and fills the cache by deserializing the contents
of the given File. |
Modifier and Type | Method and Description |
---|---|
void |
add(String absoluteFontFilePath,
FontAttributeSet attributes)
Adds the absolute path to a font and the
FontAttributeSet to be stored for that font to
the cache. |
Collection<FontSource> |
get()
To simplify the use of the
FileFontAttributesCache this method gives easy access to the
fonts included in this cache in the form of a Collection of FontSource s.Please note that this implementation does not verify that fonts that have been registered exist nor does it verify that the SeekableInputStream s in the FontSource s returned are
valid. |
Map<String,FontAttributeSet> |
getAllEntries()
Get all entries which are currently stored in the cache
|
FontAttributeSet |
getFontAttributesEntry(String absoluteFontFilePath)
Get the
FontAttributeSet cached for the font identified by the given identifier |
void |
invalidateCache()
Removes all entries from the cache.
|
void |
remove(String absoluteFontFilePath)
Removes the
FontAttributeSet for the font identified by the given identifier. |
void |
writeCache()
Persists the cache.
|
public FileFontAttributesCache(File cacheFile) throws Exception
FileFontAttributesCache
and fills the cache by deserializing the contents
of the given File. If any error occurs while filling the cache from the file the cache will be
empty.cacheFile
- the File
to store the cache at. Must not be null
.IllegalArgumentException
- is thrown if the given File is null.Exception
public void add(String absoluteFontFilePath, FontAttributeSet attributes)
FontAttributeSet
to be stored for that font to
the cache. add
in interface FontAttributesCache<String,FileNotFoundException>
absoluteFontFilePath
- an absolute path to the font to be added.attributes
- the FontAttributeSet
for the font to be addedpublic void remove(String absoluteFontFilePath)
FontAttributesCache
FontAttributeSet
for the font identified by the given identifier. If there
was no information stored for the given identifier nothing happens.remove
in interface FontAttributesCache<String,FileNotFoundException>
absoluteFontFilePath
- the identifier of the entry to remove the information for.public void invalidateCache()
FontAttributesCache
invalidateCache
in interface FontAttributesCache<String,FileNotFoundException>
public Map<String,FontAttributeSet> getAllEntries()
FontAttributesCache
getAllEntries
in interface FontAttributesCache<String,FileNotFoundException>
public FontAttributeSet getFontAttributesEntry(String absoluteFontFilePath)
FontAttributesCache
FontAttributeSet
cached for the font identified by the given identifiergetFontAttributesEntry
in interface FontAttributesCache<String,FileNotFoundException>
absoluteFontFilePath
- The identifier of the fontFontAttributeSet
for the font identified by the given identifier as stored in
the cache.null
may be returned if either there is no entry for the identifier or if
the FontAttributeSet
for the font are null
.public void writeCache() throws IOException
FontAttributesCache
writeCache
in interface FontAttributesCache<String,FileNotFoundException>
IOException
public Collection<FontSource> get() throws FileNotFoundException
FileFontAttributesCache
this method gives easy access to the
fonts included in this cache in the form of a Collection of FontSource
s.SeekableInputStream
s in the FontSource
s returned are
valid. This may lead to errors while reading from the SeekableInputStream
s provided in
the FontSource
s if invalid data was added to the cache or if the registered font no
longer exists when requested. Additionally this method is not thread-safe.get
in interface Provider<Collection<FontSource>,FileNotFoundException>
Collection
of FontSource
s based on the absolute paths and the
respective FontAttributeSet
stored in this cache.FileNotFoundException
- if an error occurs while creating the FontStreamProvider
for one of the fonts.Copyright © 2024 levigo holding gmbh. All rights reserved.