Class NIOUtilities


  • public final class NIOUtilities
    extends Object
    Utility class for managing memory mapped buffers.
    Since:
    2.0
    Author:
    Andrea Aimes
    • 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 true 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)
      • 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 a 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 {@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
      • clean

        public static boolean clean​(ByteBuffer buffer)
        Really closes a 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".
        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)