Class ArrayAllocator

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

public class ArrayAllocator extends Object implements Allocator
The ArrayAllocator object is used to provide a means to allocate buffers using a single byte array. This essentially uses the heap to allocate all buffers. As a result the performance of the resulting buffers is good, however for very large buffers this will use quote allot of the usable heap space. For very large buffers a mapped region of shared memory of a file should be considered.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    This represents the largest portion of memory that is allowed.
    private int
    This represents the default capacity of all allocated buffers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the ArrayAllocator object.
    ArrayAllocator(int size)
    Constructor for the ArrayAllocator object.
    ArrayAllocator(int size, int limit)
    Constructor for the ArrayAllocator object.
  • Method Summary

    Modifier and Type
    Method
    Description
    This method is used to allocate a default buffer.
    allocate(long size)
    This method is used to allocate a default buffer.

    Methods inherited from class java.lang.Object

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

    • limit

      private int limit
      This represents the largest portion of memory that is allowed.
    • size

      private int size
      This represents the default capacity of all allocated buffers.
  • Constructor Details

    • ArrayAllocator

      public ArrayAllocator()
      Constructor for the ArrayAllocator object. This is used to instantiate the allocator with a default buffer size of half a kilobyte. This ensures that it can be used for general purpose byte storage and for minor I/O tasks.
    • ArrayAllocator

      public ArrayAllocator(int size)
      Constructor for the ArrayAllocator object. This is used to instantiate the allocator with a specified buffer size. This is typically used when a very specific buffer capacity is required, for example a request body with a known length.
      Parameters:
      size - the initial capacity of the allocated buffers
    • ArrayAllocator

      public ArrayAllocator(int size, int limit)
      Constructor for the ArrayAllocator object. This is used to instantiate the allocator with a specified buffer size. This is typically used when a very specific buffer capacity is required, for example a request body with a known length.
      Parameters:
      size - the initial capacity of the allocated buffers
      limit - this is the maximum buffer size created by this
  • Method Details

    • allocate

      public Buffer allocate() throws IOException
      This method is used to allocate a default buffer. This will allocate a buffer of predetermined size, allowing it to grow to an upper limit to accommodate extra data. If the buffer requested is larger than the limit an exception is thrown.
      Specified by:
      allocate in interface Allocator
      Returns:
      this returns an allocated buffer with a default size
      Throws:
      IOException
    • allocate

      public Buffer allocate(long size) throws IOException
      This method is used to allocate a default buffer. This will allocate a buffer of predetermined size, allowing it to grow to an upper limit to accommodate extra data. If the buffer requested is larger than the limit an exception is thrown.
      Specified by:
      allocate in interface Allocator
      Parameters:
      size - the initial capacity of the allocated buffer
      Returns:
      this returns an allocated buffer with a default size
      Throws:
      IOException