Package org.geotools.util
Class NIOUtilities
- Object
-
- NIOUtilities
-
public final class NIOUtilities extends Object
Utility class for managing memory mapped buffers.- Since:
- 2.0
- Author:
- Andrea Aimes
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ByteBuffer
allocate(int size)
Allocates and returns aByteBuffer
.static boolean
clean(ByteBuffer buffer)
Really closes aMappedByteBuffer
without the need to wait for garbage collection.static boolean
clean(ByteBuffer buffer, boolean memoryMapped)
Depending on the type of buffer different cleanup action will be taken: if the buffer is memory mapped (as per the specified parameter) the effect is the same asclean(ByteBuffer)
if the buffer is not memory mapped it will be returned to the buffer cachestatic boolean
isDirectBuffersEnabled()
Wheter direct buffers are used, or not (defaults to true)static boolean
returnToCache(ByteBuffer buffer)
static void
setDirectBuffersEnabled(boolean directBuffersEnabled)
If the flag is trueallocate(int)
will allocate a direct buffer,, otherwise heap buffers will be used.static void
setMaxCacheSize(int maxCacheSize)
Sets the maximum byte buffer cache size, in bytes (set to 0 to only use soft references in the case, a positive value will make the cache use hard references up to the max cache size)
-
-
-
Method Detail
-
isDirectBuffersEnabled
public static boolean isDirectBuffersEnabled()
Wheter direct buffers are used, or not (defaults to true)
-
setDirectBuffersEnabled
public static void setDirectBuffersEnabled(boolean directBuffersEnabled)
If the flag is trueallocate(int)
will allocate a direct buffer,, otherwise heap buffers will be used. Direct buffers are normally faster, but their cleanup is platform dependent and not guaranteed, under high load and in combination with some garbage collectors that might result in a JVM crash (failure to perform native memory allocation)
-
setMaxCacheSize
public static void setMaxCacheSize(int maxCacheSize)
Sets the maximum byte buffer cache size, in bytes (set to 0 to only use soft references in the case, a positive value will make the cache use hard references up to the max cache size)
-
allocate
public static ByteBuffer allocate(int size)
Allocates and returns aByteBuffer
. The buffer capacity will generally be greater than of two that can contain the specified limit, the buffer limit will be set at the specified value. The buffers are pooled, so remember to call {@link #clean(ByteBuffer, false)} to return the buffer to the pool.
-
clean
public static boolean clean(ByteBuffer buffer, boolean memoryMapped)
Depending on the type of buffer different cleanup action will be taken:- if the buffer is memory mapped (as per the specified parameter) the effect is the same
as
clean(ByteBuffer)
- if the buffer is not memory mapped it will be returned to the buffer cache
- if the buffer is memory mapped (as per the specified parameter) the effect is the same
as
-
clean
public static boolean clean(ByteBuffer buffer)
Really closes aMappedByteBuffer
without the need to wait for garbage collection. Any problems with closing a buffer on Windows (the problem child in this case) will be logged asSEVERE
to the logger of the package name. To force logging of errors, set the System property "org.geotools.io.debugBuffer" to "true".- Parameters:
buffer
- The buffer to close.- Returns:
- true if the operation was successful, false otherwise.
- See Also:
MappedByteBuffer
-
returnToCache
public static boolean returnToCache(ByteBuffer buffer)
-
-