org.apache.pdfbox.io

## Class MemoryUsageSetting

- java.lang.Object
- - org.apache.pdfbox.io.MemoryUsageSetting

    public final class MemoryUsageSetting
    extends Object

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

### Field Summary

Fields
`RandomAccessStreamCache.StreamCacheCreateFunction` `streamCache` Implementation of the function to create an instance of ScratchFile using the current settings.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`long` `getMaxMainMemoryBytes()` Returns maximum size of main-memory in bytes to be used.
`long` `getMaxStorageBytes()` Returns maximum size of storage bytes to be used (main-memory in temporary files all together).
`File` `getTempDir()` Returns directory to be used for temporary files or `null` if it was not set.
`boolean` `isMainMemoryRestricted()` Returns `true` if maximum main memory is restricted to a specific number of bytes.
`boolean` `isStorageRestricted()` Returns `true` if maximum amount of storage is restricted to a specific number of bytes.
`MemoryUsageSetting` `setTempDir(File tempDir)` Sets directory to be used for temporary files.
`static MemoryUsageSetting` `setupMainMemoryOnly()` Setups buffering memory usage to only use main-memory (no temporary file) which is not restricted in size.
`static MemoryUsageSetting` `setupMainMemoryOnly(long maxMainMemoryBytes)` Setups buffering memory usage to only use main-memory with the defined maximum.
`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.
`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.
`static MemoryUsageSetting` `setupTempFileOnly()` Setups buffering memory usage to only use temporary file(s) (no main-memory) with not restricted size.
`static MemoryUsageSetting` `setupTempFileOnly(long maxStorageBytes)` Setups buffering memory usage to only use temporary file(s) (no main-memory) with the specified maximum size.
`String` `toString()`
`boolean` `useMainMemory()` Returns `true` if main-memory is to be used.
`boolean` `useTempFile()` Returns `true` if temporary file is to be used.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### streamCache

    public final RandomAccessStreamCache.StreamCacheCreateFunction streamCache

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

### Method Detail

#### setupMainMemoryOnly

    public static MemoryUsageSetting 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

    public static MemoryUsageSetting setupMainMemoryOnly(long maxMainMemoryBytes)

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

Parameters:
  `maxMainMemoryBytes` - maximum number of main-memory to be used; `-1` for no restriction; `0` will also be interpreted here as no restriction
Returns:
  returns an instance of MemoryUsageSetting set up to use main memory

#### setupTempFileOnly

    public static MemoryUsageSetting 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

    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` - maximum size the temporary file(s) may have all together; `-1` for no restriction; `0` will also be interpreted here as no restriction
Returns:
  returns an instance of MemoryUsageSetting set up to use temporary files with restricted size

#### setupMixed

    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` - 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:
  returns an instance of MemoryUsageSetting set up to use a mixed setting

#### setupMixed

    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` - 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` - 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:
  returns an instance of MemoryUsageSetting set up to use a mixed setting

#### setTempDir

    public MemoryUsageSetting setTempDir(File tempDir)

Sets directory to be used for temporary files.

Parameters:
  `tempDir` - directory for temporary files
Returns:
  this instance

#### useMainMemory

    public boolean useMainMemory()

Returns `true` if main-memory is to be used.

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

Returns:
  true if this instance is set up to use main memory

#### useTempFile

    public boolean useTempFile()

Returns `true` if temporary file is to be used.

If this returns `false` it is ensured `useMainMemory` returns `true`.

Returns:
  true if this instance is set up to use temporary files

#### isMainMemoryRestricted

    public boolean isMainMemoryRestricted()

Returns `true` if 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()

Returns `true` if 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

    public File getTempDir()

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

Returns:
  the temp dir to bes used for temporary files or null

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`