Package org.apache.pdfbox.pdmodel
Class DefaultResourceCache
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.DefaultResourceCache
-
- All Implemented Interfaces:
ResourceCache
public class DefaultResourceCache extends java.lang.Object implements ResourceCache
A resource cached based on SoftReference, retains resources until memory pressure causes them to be garbage collected. Cached resources may be removed pro actively. Resources which are removed and added several times, can't be removed after hitting the threshold of 3. This may happen if resources are shared among several pages. This kind of stable caching is enabled by default and can be deactivated.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<COSObject,java.lang.ref.SoftReference<PDColorSpace>>colorSpacesprivate java.util.Map<COSObject,java.lang.ref.SoftReference<PDExtendedGraphicsState>>extGStatesprivate java.util.Map<COSObject,java.lang.ref.SoftReference<PDFont>>fontsprivate static intmaxRemovalsprivate java.util.Map<COSObject,java.lang.ref.SoftReference<PDAbstractPattern>>patternsprivate java.util.Map<COSObject,java.lang.ref.SoftReference<PDPropertyList>>propertiesprivate java.util.Map<java.lang.Long,java.lang.Integer>removedColorSpacesprivate java.util.Map<java.lang.Long,java.lang.Integer>removedExtGStatesprivate java.util.Map<java.lang.Long,java.lang.Integer>removedFontsprivate java.util.Map<java.lang.Long,java.lang.Integer>removedPatternsprivate java.util.Map<java.lang.Long,java.lang.Integer>removedPropertiesprivate java.util.Map<java.lang.Long,java.lang.Integer>removedShadingsprivate java.util.Map<java.lang.Long,java.lang.Integer>removedXObjectsprivate java.util.Map<COSObject,java.lang.ref.SoftReference<PDShading>>shadingsprivate booleanstableCacheEnabledprivate java.util.Set<java.lang.Long>stableColorSpacesprivate java.util.Set<java.lang.Long>stableExtGStatesprivate java.util.Set<java.lang.Long>stableFontsprivate java.util.Set<java.lang.Long>stablePatternsprivate java.util.Set<java.lang.Long>stablePropertiesprivate java.util.Set<java.lang.Long>stableShadingsprivate java.util.Set<java.lang.Long>stableXObjectprivate java.util.Map<COSObject,java.lang.ref.SoftReference<PDXObject>>xobjects
-
Constructor Summary
Constructors Constructor Description DefaultResourceCache()Default constructor.DefaultResourceCache(boolean enableStableCache)Constructor providing a parameter to enable/disable the stable object cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PDColorSpacegetColorSpace(COSObject indirect)Returns the color space resource for the given indirect object, if it is in the cache.PDExtendedGraphicsStategetExtGState(COSObject indirect)Returns the extended graphics state resource for the given indirect object, if it is in the cache.PDFontgetFont(COSObject indirect)Returns the font resource for the given indirect object, if it is in the cache.PDAbstractPatterngetPattern(COSObject indirect)Returns the pattern resource for the given indirect object, if it is in the cache.PDPropertyListgetProperties(COSObject indirect)Returns the property list resource for the given indirect object, if it is in the cache.PDShadinggetShading(COSObject indirect)Returns the shading resource for the given indirect object, if it is in the cache.PDXObjectgetXObject(COSObject indirect)Returns the XObject resource for the given indirect object, if it is in the cache.voidput(COSObject indirect, PDPropertyList propertyList)Puts the given indirect property list resource in the cache.voidput(COSObject indirect, PDFont font)Puts the given indirect font resource in the cache.voidput(COSObject indirect, PDColorSpace colorSpace)Puts the given indirect color space resource in the cache.voidput(COSObject indirect, PDAbstractPattern pattern)Puts the given indirect pattern resource in the cache.voidput(COSObject indirect, PDXObject xobject)Puts the given indirect XObject resource in the cache.voidput(COSObject indirect, PDShading shading)Puts the given indirect shading resource in the cache.voidput(COSObject indirect, PDExtendedGraphicsState extGState)Puts the given indirect extended graphics state resource in the cache.PDColorSpaceremoveColorSpace(COSObject indirect)Removes the given indirect color space resource from the cache.PDExtendedGraphicsStateremoveExtState(COSObject indirect)Removes the given indirect extended graphics state resource from the cache.PDFontremoveFont(COSObject indirect)Removes the given indirect font resource from the cache.PDAbstractPatternremovePattern(COSObject indirect)Removes the given indirect pattern resource from the cache.PDPropertyListremoveProperties(COSObject indirect)Removes the given indirect property list resource from the cache.PDShadingremoveShading(COSObject indirect)Removes the given indirect shading resource from the cache.PDXObjectremoveXObject(COSObject indirect)Removes the given indirect XObject resource from the cache.
-
-
-
Field Detail
-
maxRemovals
private static final int maxRemovals
- See Also:
- Constant Field Values
-
stableCacheEnabled
private final boolean stableCacheEnabled
-
removedFonts
private final java.util.Map<java.lang.Long,java.lang.Integer> removedFonts
-
stableFonts
private final java.util.Set<java.lang.Long> stableFonts
-
colorSpaces
private final java.util.Map<COSObject,java.lang.ref.SoftReference<PDColorSpace>> colorSpaces
-
removedColorSpaces
private final java.util.Map<java.lang.Long,java.lang.Integer> removedColorSpaces
-
stableColorSpaces
private final java.util.Set<java.lang.Long> stableColorSpaces
-
removedXObjects
private final java.util.Map<java.lang.Long,java.lang.Integer> removedXObjects
-
stableXObject
private final java.util.Set<java.lang.Long> stableXObject
-
extGStates
private final java.util.Map<COSObject,java.lang.ref.SoftReference<PDExtendedGraphicsState>> extGStates
-
removedExtGStates
private final java.util.Map<java.lang.Long,java.lang.Integer> removedExtGStates
-
stableExtGStates
private final java.util.Set<java.lang.Long> stableExtGStates
-
removedShadings
private final java.util.Map<java.lang.Long,java.lang.Integer> removedShadings
-
stableShadings
private final java.util.Set<java.lang.Long> stableShadings
-
patterns
private final java.util.Map<COSObject,java.lang.ref.SoftReference<PDAbstractPattern>> patterns
-
removedPatterns
private final java.util.Map<java.lang.Long,java.lang.Integer> removedPatterns
-
stablePatterns
private final java.util.Set<java.lang.Long> stablePatterns
-
properties
private final java.util.Map<COSObject,java.lang.ref.SoftReference<PDPropertyList>> properties
-
removedProperties
private final java.util.Map<java.lang.Long,java.lang.Integer> removedProperties
-
stableProperties
private final java.util.Set<java.lang.Long> stableProperties
-
-
Constructor Detail
-
DefaultResourceCache
public DefaultResourceCache()
Default constructor.
-
DefaultResourceCache
public DefaultResourceCache(boolean enableStableCache)
Constructor providing a parameter to enable/disable the stable object cache.- Parameters:
enableStableCache- enables/disables the stable object cache
-
-
Method Detail
-
getFont
public PDFont getFont(COSObject indirect)
Description copied from interface:ResourceCacheReturns the font resource for the given indirect object, if it is in the cache.- Specified by:
getFontin interfaceResourceCache- Parameters:
indirect- the indirect reference of the font to be returned- Returns:
- the cached instance of the referenced font, if available
-
put
public void put(COSObject indirect, PDFont font)
Description copied from interface:ResourceCachePuts the given indirect font resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the font to be cachedfont- the font to be cached
-
removeFont
public PDFont removeFont(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect font resource from the cache.- Specified by:
removeFontin interfaceResourceCache- Parameters:
indirect- the indirect reference of the font to be removed- Returns:
- the removed resource if present
-
getColorSpace
public PDColorSpace getColorSpace(COSObject indirect)
Description copied from interface:ResourceCacheReturns the color space resource for the given indirect object, if it is in the cache.- Specified by:
getColorSpacein interfaceResourceCache- Parameters:
indirect- the indirect reference of the colorspace to be returned- Returns:
- the cached instance of the referenced colorspace, if available
-
put
public void put(COSObject indirect, PDColorSpace colorSpace)
Description copied from interface:ResourceCachePuts the given indirect color space resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the colorspace to be cachedcolorSpace- the colorspace to be cached
-
removeColorSpace
public PDColorSpace removeColorSpace(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect color space resource from the cache.- Specified by:
removeColorSpacein interfaceResourceCache- Parameters:
indirect- the indirect reference of the color space to be removed- Returns:
- the removed resource if present
-
getExtGState
public PDExtendedGraphicsState getExtGState(COSObject indirect)
Description copied from interface:ResourceCacheReturns the extended graphics state resource for the given indirect object, if it is in the cache.- Specified by:
getExtGStatein interfaceResourceCache- Parameters:
indirect- the indirect reference of the extended graphics state to be returned- Returns:
- the cached instance of the referenced extended graphics state, if available
-
put
public void put(COSObject indirect, PDExtendedGraphicsState extGState)
Description copied from interface:ResourceCachePuts the given indirect extended graphics state resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the extended graphics state to be cachedextGState- the extended graphics state to be cached
-
removeExtState
public PDExtendedGraphicsState removeExtState(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect extended graphics state resource from the cache.- Specified by:
removeExtStatein interfaceResourceCache- Parameters:
indirect- the indirect reference of the extended graphics state to be removed- Returns:
- the removed resource if present
-
getShading
public PDShading getShading(COSObject indirect)
Description copied from interface:ResourceCacheReturns the shading resource for the given indirect object, if it is in the cache.- Specified by:
getShadingin interfaceResourceCache- Parameters:
indirect- the indirect reference of the shading to be returned- Returns:
- the cached instance of the referenced shading, if available
-
put
public void put(COSObject indirect, PDShading shading)
Description copied from interface:ResourceCachePuts the given indirect shading resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the shading to be cachedshading- the shading to be cached
-
removeShading
public PDShading removeShading(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect shading resource from the cache.- Specified by:
removeShadingin interfaceResourceCache- Parameters:
indirect- the indirect reference of the shading to be removed- Returns:
- the removed resource if present
-
getPattern
public PDAbstractPattern getPattern(COSObject indirect)
Description copied from interface:ResourceCacheReturns the pattern resource for the given indirect object, if it is in the cache.- Specified by:
getPatternin interfaceResourceCache- Parameters:
indirect- the indirect reference of the pattern to be returned- Returns:
- the cached instance of the referenced pattern, if available
-
put
public void put(COSObject indirect, PDAbstractPattern pattern)
Description copied from interface:ResourceCachePuts the given indirect pattern resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the pattern to be cachedpattern- the pattern to be cached
-
removePattern
public PDAbstractPattern removePattern(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect pattern resource from the cache.- Specified by:
removePatternin interfaceResourceCache- Parameters:
indirect- the indirect reference of the pattern to be removed- Returns:
- the removed resource if present
-
getProperties
public PDPropertyList getProperties(COSObject indirect)
Description copied from interface:ResourceCacheReturns the property list resource for the given indirect object, if it is in the cache.- Specified by:
getPropertiesin interfaceResourceCache- Parameters:
indirect- the indirect reference of the property list to be returned- Returns:
- the cached instance of the referenced property list, if available
-
put
public void put(COSObject indirect, PDPropertyList propertyList)
Description copied from interface:ResourceCachePuts the given indirect property list resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the property list to be cachedpropertyList- the property list to be cached
-
removeProperties
public PDPropertyList removeProperties(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect property list resource from the cache.- Specified by:
removePropertiesin interfaceResourceCache- Parameters:
indirect- the indirect reference of the property list to be removed- Returns:
- the removed resource if present
-
getXObject
public PDXObject getXObject(COSObject indirect)
Description copied from interface:ResourceCacheReturns the XObject resource for the given indirect object, if it is in the cache.- Specified by:
getXObjectin interfaceResourceCache- Parameters:
indirect- the indirect reference of the XObject to be returned- Returns:
- the cached instance of the referenced XObject, if available
-
put
public void put(COSObject indirect, PDXObject xobject)
Description copied from interface:ResourceCachePuts the given indirect XObject resource in the cache.- Specified by:
putin interfaceResourceCache- Parameters:
indirect- the indirect reference of the XObject to be cachedxobject- the XObject to be cached
-
removeXObject
public PDXObject removeXObject(COSObject indirect)
Description copied from interface:ResourceCacheRemoves the given indirect XObject resource from the cache.- Specified by:
removeXObjectin interfaceResourceCache- Parameters:
indirect- the indirect reference of the XObject to be removed- Returns:
- the removed resource if present
-
-