Top Description Fields Constructors Methods
org.apache.pdfbox.io

public final Class MemoryUsageSetting

extends Object
Class Inheritance
Imports
java.io.File, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction

Controls how memory/temporary files are used for buffering streams etc.

Field Summary

Modifier and TypeField and Description
private final long
maxMainMemoryBytes

maximum number of main-memory bytes allowed to be used; -1 means 'unrestricted'

private final long
maxStorageBytes

maximum number of bytes allowed for storage at all (main-memory+file); -1 means 'unrestricted'

public final RandomAccessStreamCache.StreamCacheCreateFunction
streamCache

Implementation of the function to create an instance of ScratchFile using the current settings.

private File
tempDir

directory to be used for scratch file

private final boolean
private final boolean

Constructor Summary

AccessConstructor and Description
private
MemoryUsageSetting(boolean
if true main memory usage is enabled; in case of false and useTempFile is false too we set this to true
useMainMemory
,
boolean
if true using of temporary file(s) is enabled
useTempFile
,
long
maximum number of main-memory to be used; if -1 means 'unrestricted'; if 0 we only use temporary file if useTempFile is true otherwise main-memory usage will have restriction defined by maxStorageBytes
maxMainMemoryBytes
,
long
maximum size the main-memory and temporary file(s) may have all together; 0 or less will be ignored; if it is less than maxMainMemoryBytes we use maxMainMemoryBytes value instead
maxStorageBytes
)

Private constructor for setup buffering memory usage called by one of the setup methods.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the maximum number of main-memory in bytes to be used
getMaxMainMemoryBytes
()

Returns maximum size of main-memory in bytes to be used.

public long

Returns:

the maximum size of storage bytes to be used
getMaxStorageBytes
()

Returns maximum size of storage bytes to be used (main-memory in temporary files all together).

public File

Returns:

the temp dir to bes used for temporary files or null
getTempDir
()

Returns directory to be used for temporary files or null if it was not set.

public boolean

Returns:

true if this instance is set up to restrict main memory
isMainMemoryRestricted
()

Returns true if maximum main memory is restricted to a specific number of bytes.

public boolean

Returns:

true if this instance is set up to restrict storage size
isStorageRestricted
()

Returns true if maximum amount of storage is restricted to a specific number of bytes.

public MemoryUsageSetting

Returns:

this instance
setTempDir
(File
directory for temporary files
tempDir
)

Sets directory to be used for temporary files.

public static MemoryUsageSetting

Returns:

returns an instance of MemoryUsageSetting set up to use unlimited memory
setupMainMemoryOnly
()

Setups buffering memory usage to only use main-memory (no temporary file) which is not restricted in size.

public static MemoryUsageSetting

Returns:

returns an instance of MemoryUsageSetting set up to use main memory
setupMainMemoryOnly
(long
maximum number of main-memory to be used; -1 for no restriction; 0 will also be interpreted here as no restriction
maxMainMemoryBytes
)

Setups buffering memory usage to only use main-memory with the defined maximum.

public static MemoryUsageSetting

Returns:

returns an instance of MemoryUsageSetting set up to use a mixed setting
setupMixed
(long
maximum number of main-memory to be used; if -1 this is the same as setupMainMemoryOnly(); if 0 this is the same as setupTempFileOnly()
maxMainMemoryBytes
)

Setups buffering memory usage to use a portion of main-memory and additionally temporary file(s) in case the specified portion is exceeded.

public static MemoryUsageSetting

Returns:

returns an instance of MemoryUsageSetting set up to use a mixed setting
setupMixed
(long
maximum number of main-memory to be used; if -1 this is the same as setupMainMemoryOnly(); if 0 this is the same as setupTempFileOnly()
maxMainMemoryBytes
,
long
maximum size the main-memory and temporary file(s) may have all together; 0 or less will be ignored; if it is less than maxMainMemoryBytes we use maxMainMemoryBytes value instead
maxStorageBytes
)

Setups buffering memory usage to use a portion of main-memory and additionally temporary file(s) in case the specified portion is exceeded.

public static MemoryUsageSetting

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 not restricted size.

public static MemoryUsageSetting

Returns:

returns an instance of MemoryUsageSetting set up to use temporary files with restricted size
setupTempFileOnly
(long
maximum size the temporary file(s) may have all together; -1 for no restriction; 0 will also be interpreted here as no restriction
maxStorageBytes
)

Setups buffering memory usage to only use temporary file(s) (no main-memory) with the specified maximum size.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public boolean

Returns:

true if this instance is set up to use main memory
useMainMemory
()

Returns true if main-memory is to be used.

public boolean

Returns:

true if this instance is set up to use temporary files
useTempFile
()

Returns true if temporary file is to be used.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

maxMainMemoryBytesback to summary
private final long maxMainMemoryBytes

maximum number of main-memory bytes allowed to be used; -1 means 'unrestricted'

maxStorageBytesback to summary
private final long maxStorageBytes

maximum number of bytes allowed for storage at all (main-memory+file); -1 means 'unrestricted'

streamCacheback to summary
public final RandomAccessStreamCache.StreamCacheCreateFunction streamCache

Implementation of the function to create an instance of ScratchFile using the current settings.

tempDirback to summary
private File tempDir

directory to be used for scratch file

useMainMemoryback to summary
private final boolean useMainMemory
useTempFileback to summary
private final boolean useTempFile

Constructor Detail

MemoryUsageSettingback to summary
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:boolean

if true main memory usage is enabled; in case of false and useTempFile is false too we set this to true

useTempFile:boolean

if true using of temporary file(s) is enabled

maxMainMemoryBytes:long

maximum number of main-memory to be used; if -1 means 'unrestricted'; if 0 we only use temporary file if useTempFile is true otherwise main-memory usage will have restriction defined by maxStorageBytes

maxStorageBytes:long

maximum size the main-memory and temporary file(s) may have all together; 0 or less will be ignored; if it is less than maxMainMemoryBytes we use maxMainMemoryBytes value instead

Method Detail

getMaxMainMemoryBytesback to summary
public long getMaxMainMemoryBytes()

Returns maximum size of main-memory in bytes to be used.

Returns:long

the maximum number of main-memory in bytes to be used

getMaxStorageBytesback to summary
public long getMaxStorageBytes()

Returns maximum size of storage bytes to be used (main-memory in temporary files all together).

Returns:long

the maximum size of storage bytes to be used

getTempDirback to summary
public File getTempDir()

Returns directory to be used for temporary files or null if it was not set.

Returns:File

the temp dir to bes used for temporary files or null

isMainMemoryRestrictedback to summary
public boolean isMainMemoryRestricted()

Returns true if maximum main memory is restricted to a specific number of bytes.

Returns:boolean

true if this instance is set up to restrict main memory

isStorageRestrictedback to summary
public boolean isStorageRestricted()

Returns true if maximum amount of storage is restricted to a specific number of bytes.

Returns:boolean

true if this instance is set up to restrict storage size

setTempDirback to summary
public MemoryUsageSetting setTempDir(File tempDir)

Sets directory to be used for temporary files.

Parameters
tempDir:File

directory for temporary files

Returns:MemoryUsageSetting

this instance

setupMainMemoryOnlyback to summary
public static MemoryUsageSetting setupMainMemoryOnly()

Setups buffering memory usage to only use main-memory (no temporary file) which is not restricted in size.

Returns:MemoryUsageSetting

returns an instance of MemoryUsageSetting set up to use unlimited memory

setupMainMemoryOnlyback to summary
public static MemoryUsageSetting setupMainMemoryOnly(long maxMainMemoryBytes)

Setups buffering memory usage to only use main-memory with the defined maximum.

Parameters
maxMainMemoryBytes:long

maximum number of main-memory to be used; -1 for no restriction; 0 will also be interpreted here as no restriction

Returns:MemoryUsageSetting

returns an instance of MemoryUsageSetting set up to use main memory

setupMixedback to summary
public static MemoryUsageSetting setupMixed(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.

Parameters
maxMainMemoryBytes:long

maximum number of main-memory to be used; if -1 this is the same as setupMainMemoryOnly(); if 0 this is the same as setupTempFileOnly()

Returns:MemoryUsageSetting

returns an instance of MemoryUsageSetting set up to use a mixed setting

setupMixedback to summary
public static MemoryUsageSetting setupMixed(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.

Parameters
maxMainMemoryBytes:long

maximum number of main-memory to be used; if -1 this is the same as setupMainMemoryOnly(); if 0 this is the same as setupTempFileOnly()

maxStorageBytes:long

maximum size the main-memory and temporary file(s) may have all together; 0 or less will be ignored; if it is less than maxMainMemoryBytes we use maxMainMemoryBytes value instead

Returns:MemoryUsageSetting

returns an instance of MemoryUsageSetting set up to use a mixed setting

setupTempFileOnlyback to summary
public static MemoryUsageSetting setupTempFileOnly()

Setups buffering memory usage to only use temporary file(s) (no main-memory) with not restricted size.

Returns:MemoryUsageSetting

returns an instance of MemoryUsageSetting set up to use temporary files with not restricted size

setupTempFileOnlyback to summary
public static MemoryUsageSetting setupTempFileOnly(long maxStorageBytes)

Setups buffering memory usage to only use temporary file(s) (no main-memory) with the specified maximum size.

Parameters
maxStorageBytes:long

maximum size the temporary file(s) may have all together; -1 for no restriction; 0 will also be interpreted here as no restriction

Returns:MemoryUsageSetting

returns an instance of MemoryUsageSetting set up to use temporary files with restricted size

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
useMainMemoryback to summary
public boolean useMainMemory()

Returns true if main-memory is to be used.

If this returns false it is ensured useTempFile() returns true.

Returns:boolean

true if this instance is set up to use main memory

useTempFileback to summary
public boolean useTempFile()

Returns true if temporary file is to be used.

If this returns false it is ensured useMainMemory returns true.

Returns:boolean

true if this instance is set up to use temporary files