Package org.apache.pdfbox.io
Class MemoryUsageSetting
java.lang.Object
org.apache.pdfbox.io.MemoryUsageSetting
Controls how memory/temporary files are used for
buffering streams etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longmaximum number of main-memory bytes allowed to be used;-1means 'unrestricted'private final longmaximum number of bytes allowed for storage at all (main-memory+file);-1means 'unrestricted'Implementation of the function to create an instance of ScratchFile using the current settings.private Filedirectory to be used for scratch fileprivate final booleanprivate final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateMemoryUsageSetting(boolean useMainMemory, boolean useTempFile, long maxMainMemoryBytes, long maxStorageBytes) Private constructor for setup buffering memory usage called by one of the setup methods. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns maximum size of main-memory in bytes to be used.longReturns maximum size of storage bytes to be used (main-memory in temporary files all together).Returns directory to be used for temporary files ornullif it was not set.booleanReturnstrueif maximum main memory is restricted to a specific number of bytes.booleanReturnstrueif maximum amount of storage is restricted to a specific number of bytes.setTempDir(File tempDir) Sets directory to be used for temporary files.static MemoryUsageSettingSetups buffering memory usage to only use main-memory (no temporary file) which is not restricted in size.static MemoryUsageSettingsetupMainMemoryOnly(long maxMainMemoryBytes) Setups buffering memory usage to only use main-memory with the defined maximum.static MemoryUsageSettingsetupMixed(long maxMainMemoryBytes) Setups buffering memory usage to use a portion of main-memory and additionally temporary file(s) in case the specified portion is exceeded.static MemoryUsageSettingsetupMixed(long maxMainMemoryBytes, long maxStorageBytes) Setups buffering memory usage to use a portion of main-memory and additionally temporary file(s) in case the specified portion is exceeded.static MemoryUsageSettingSetups buffering memory usage to only use temporary file(s) (no main-memory) with not restricted size.static MemoryUsageSettingsetupTempFileOnly(long maxStorageBytes) Setups buffering memory usage to only use temporary file(s) (no main-memory) with the specified maximum size.toString()booleanReturnstrueif main-memory is to be used.booleanReturnstrueif temporary file is to be used.
-
Field Details
-
useMainMemory
private final boolean useMainMemory -
useTempFile
private final boolean useTempFile -
maxMainMemoryBytes
private final long maxMainMemoryBytesmaximum number of main-memory bytes allowed to be used;-1means 'unrestricted' -
maxStorageBytes
private final long maxStorageBytesmaximum number of bytes allowed for storage at all (main-memory+file);-1means 'unrestricted' -
tempDir
directory to be used for scratch file -
streamCache
Implementation of the function to create an instance of ScratchFile using the current settings.
-
-
Constructor Details
-
MemoryUsageSetting
private MemoryUsageSetting(boolean useMainMemory, boolean useTempFile, long maxMainMemoryBytes, long maxStorageBytes) Private constructor for setup buffering memory usage called by one of the setup methods.- Parameters:
useMainMemory- iftruemain memory usage is enabled; in case offalseanduseTempFileisfalsetoo we set this totrueuseTempFile- iftrueusing of temporary file(s) is enabledmaxMainMemoryBytes- maximum number of main-memory to be used; if-1means 'unrestricted'; if0we only use temporary file ifuseTempFileistrueotherwise main-memory usage will have restriction defined by maxStorageBytesmaxStorageBytes- maximum size the main-memory and temporary file(s) may have all together;0or less will be ignored; if it is less than maxMainMemoryBytes we use maxMainMemoryBytes value instead
-
-
Method Details
-
setupMainMemoryOnly
Setups buffering memory usage to only use main-memory (no temporary file) which is not restricted in size.- Returns:
- returns an instance of MemoryUsageSetting set up to use unlimited memory
-
setupMainMemoryOnly
Setups buffering memory usage to only use main-memory with the defined maximum.- Parameters:
maxMainMemoryBytes- maximum number of main-memory to be used;-1for no restriction;0will also be interpreted here as no restriction- Returns:
- returns an instance of MemoryUsageSetting set up to use main memory
-
setupTempFileOnly
Setups buffering memory usage to only use temporary file(s) (no main-memory) with not restricted size.- Returns:
- returns an instance of MemoryUsageSetting set up to use temporary files with not restricted size
-
setupTempFileOnly
Setups buffering memory usage to only use temporary file(s) (no main-memory) with the specified maximum size.- Parameters:
maxStorageBytes- maximum size the temporary file(s) may have all together;-1for no restriction;0will also be interpreted here as no restriction- Returns:
- returns an instance of MemoryUsageSetting set up to use temporary files with restricted size
-
setupMixed
Setups buffering memory usage to use a portion of main-memory and additionally temporary file(s) in case the specified portion is exceeded.- Parameters:
maxMainMemoryBytes- maximum number of main-memory to be used; if-1this is the same assetupMainMemoryOnly(); if0this is the same assetupTempFileOnly()- Returns:
- returns an instance of MemoryUsageSetting set up to use a mixed setting
-
setupMixed
Setups buffering memory usage to use a portion of main-memory and additionally temporary file(s) in case the specified portion is exceeded.- Parameters:
maxMainMemoryBytes- maximum number of main-memory to be used; if-1this is the same assetupMainMemoryOnly(); if0this is the same assetupTempFileOnly()maxStorageBytes- maximum size the main-memory and temporary file(s) may have all together;0or less will be ignored; if it is less than maxMainMemoryBytes we use maxMainMemoryBytes value instead- Returns:
- returns an instance of MemoryUsageSetting set up to use a mixed setting
-
setTempDir
Sets directory to be used for temporary files.- Parameters:
tempDir- directory for temporary files- Returns:
- this instance
-
useMainMemory
public boolean useMainMemory()Returnstrueif main-memory is to be used.If this returns
falseit is ensureduseTempFile()returnstrue.- Returns:
- true if this instance is set up to use main memory
-
useTempFile
public boolean useTempFile()Returnstrueif temporary file is to be used.If this returns
falseit is ensureduseMainMemoryreturnstrue.- Returns:
- true if this instance is set up to use temporary files
-
isMainMemoryRestricted
public boolean isMainMemoryRestricted()Returnstrueif maximum main memory is restricted to a specific number of bytes.- Returns:
- true if this instance is set up to restrict main memory
-
isStorageRestricted
public boolean isStorageRestricted()Returnstrueif maximum amount of storage is restricted to a specific number of bytes.- Returns:
- true if this instance is set up to restrict storage size
-
getMaxMainMemoryBytes
public long getMaxMainMemoryBytes()Returns maximum size of main-memory in bytes to be used.- Returns:
- the maximum number of main-memory in bytes to be used
-
getMaxStorageBytes
public long getMaxStorageBytes()Returns maximum size of storage bytes to be used (main-memory in temporary files all together).- Returns:
- the maximum size of storage bytes to be used
-
getTempDir
Returns directory to be used for temporary files ornullif it was not set.- Returns:
- the temp dir to bes used for temporary files or null
-
toString
-