Class FileAllocator

java.lang.Object
org.simpleframework.common.buffer.FileAllocator
All Implemented Interfaces:
Allocator

public class FileAllocator extends Object implements Allocator
The FileAllocator object is used to create buffers that can be written to the file system. This creates buffers as files if they are larger than the specified limit. This ensures that buffers of arbitrary large size can be created. All buffer sizes under the limit are created using byte arrays allocated on the executing VM heap. This ensures that optimal performance is maintained for buffers of reasonable size.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    This is the limit up to which buffers are allocated in memory.
    private FileWatcher
    This is the file manager used to create the buffer files.
    private static final String
    This is the default prefix used when none has been specified.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the FileAllocator object.
    FileAllocator(int limit)
    Constructor for the FileAllocator object.
    Constructor for the FileAllocator object.
    FileAllocator(String prefix, int limit)
    Constructor for the FileAllocator object.
  • Method Summary

    Modifier and Type
    Method
    Description
    This will allocate a file buffer which will write data for the buffer to a file.
    allocate(long size)
    This will allocate a file buffer which will write data for the buffer to a file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PREFIX

      private static final String PREFIX
      This is the default prefix used when none has been specified.
      See Also:
    • manager

      private FileWatcher manager
      This is the file manager used to create the buffer files.
    • limit

      private int limit
      This is the limit up to which buffers are allocated in memory.
  • Constructor Details

    • FileAllocator

      public FileAllocator()
      Constructor for the FileAllocator object. This is used to create buffers in memory up to a threshold size. If a buffer is required over the threshold size then the data is written to a file, where it can be retrieved at a later point.
    • FileAllocator

      public FileAllocator(int limit)
      Constructor for the FileAllocator object. This is used to create buffers in memory up to a threshold size. If a buffer is required over the threshold size then the data is written to a file, where it can be retrieved at a later point.
      Parameters:
      limit - this is the maximum size for a heap buffer
    • FileAllocator

      public FileAllocator(String prefix)
      Constructor for the FileAllocator object. This is used to create buffers in memory up to a threshold size. If a buffer is required over the threshold size then the data is written to a file, where it can be retrieved at a later point.
      Parameters:
      prefix - this is the file prefix for the file buffers
    • FileAllocator

      public FileAllocator(String prefix, int limit)
      Constructor for the FileAllocator object. This is used to create buffers in memory up to a threshold size. If a buffer is required over the threshold size then the data is written to a file, where it can be retrieved at a later point.
      Parameters:
      prefix - this is the file prefix for the file buffers
      limit - this is the maximum size for a heap buffer
  • Method Details

    • allocate

      public Buffer allocate() throws IOException
      This will allocate a file buffer which will write data for the buffer to a file. Buffers allocated by this method can be of arbitrary size as data is appended directly to a temporary file. This ensures there is no upper limit for appended data.
      Specified by:
      allocate in interface Allocator
      Returns:
      a buffer which will write to a temporary file
      Throws:
      IOException
    • allocate

      public Buffer allocate(long size) throws IOException
      This will allocate a file buffer which will write data for the buffer to a file. Buffers allocated by this method can be of arbitrary size as data is appended directly to a temporary file. This ensures there is no upper limit for appended data. If the size required is less than the limit then the buffer is an in memory array which provides optimal performance.
      Specified by:
      allocate in interface Allocator
      Parameters:
      size - this is the size of the buffer to be created
      Returns:
      a buffer which will write to a created temporary file
      Throws:
      IOException