Package org.simpleframework.util.buffer
Class ArrayAllocator
- java.lang.Object
-
- org.simpleframework.util.buffer.ArrayAllocator
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Allocator
public class ArrayAllocator extends java.lang.Object implements Allocator
TheArrayAllocatorobject 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.- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description ArrayAllocator()Constructor for theArrayAllocatorobject.ArrayAllocator(int size)Constructor for theArrayAllocatorobject.ArrayAllocator(int size, int limit)Constructor for theArrayAllocatorobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bufferallocate()This method is used to allocate a default buffer.Bufferallocate(int size)This method is used to allocate a default buffer.voidclose()This method is used to close the allocator so that resources that are occupied by the allocator can be freed.
-
-
-
Constructor Detail
-
ArrayAllocator
public ArrayAllocator()
Constructor for theArrayAllocatorobject. 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 theArrayAllocatorobject. 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 theArrayAllocatorobject. 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 bufferslimit- this is the maximum buffer size created by this
-
-
Method Detail
-
allocate
public Buffer allocate() throws java.io.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 accomodate extra data. If the buffer requested is larger than the limit an exception is thrown.
-
allocate
public Buffer allocate(int size) throws java.io.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 accomodate extra data. If the buffer requested is larger than the limit an exception is thrown.
-
close
public void close() throws java.io.IOExceptionThis method is used to close the allocator so that resources that are occupied by the allocator can be freed. This will allow the allocator to be created and closed repeatedly in a single process without holding on to resources such as mapped file buffers or threads.
-
-