public final class NIOUtilities extends Object
Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
allocate(int size)
Allocates and returns a
ByteBuffer . |
static boolean |
clean(ByteBuffer buffer)
Really closes a
MappedByteBuffer 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
as
clean(ByteBuffer)
if the buffer is not memory mapped it will be returned to the buffer cache
|
static 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 true
allocate(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)
|
public static boolean isDirectBuffersEnabled()
public static void setDirectBuffersEnabled(boolean directBuffersEnabled)
allocate(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)directBuffersEnabled
- public static void setMaxCacheSize(int maxCacheSize)
maxCacheSize
- public static ByteBuffer allocate(int size)
ByteBuffer
. 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 #clean(ByteBuffer,
false)
to return the buffer to the pool.limit
- public static boolean clean(ByteBuffer buffer, boolean memoryMapped)
clean(ByteBuffer)
buffer
- public static boolean clean(ByteBuffer buffer)
MappedByteBuffer
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 as
SEVERE
to the logger of the package name. To force logging of errors, set the System
property "org.geotools.io.debugBuffer" to "true".
Starting from Java 9 the underlying Java runtime issue got fixed, so the method returns immediately in that case, without forcing any cleaning by reflection on a non exposed API
buffer
- The buffer to close.MappedByteBuffer
public static boolean returnToCache(ByteBuffer buffer)
Copyright © 1996–2019 Geotools. All rights reserved.