Class PersistentCollections

java.lang.Object
com.aoapps.persistence.PersistentCollections

public final class PersistentCollections extends Object
A set of static utility methods to help in the selection, creation, and management of persistent collections.
Author:
AO Industries, Inc.
  • Method Details

    • ensureZeros

      public static boolean ensureZeros(RandomAccessFile raf, long position, long count) throws IOException
      Writes the requested number of zeros to the provided RandomAccessFile, but only if they do not already contain zeros. This is to avoid unnecessary writes on flash media. This may also have a positive interaction with sparse files.
      Returns:
      true when the byteBuffer was written to
      Throws:
      IOException
    • ensureZeros

      public static boolean ensureZeros(ByteBuffer byteBuffer, int position, int count)
      Stores the requested number of zeros to the provided ByteBuffer, but only if they do not already contain zeros. This is to avoid unnecessary writes on flash media. This may also have a positive interaction with sparse files.
      Returns:
      true when the byteBuffer was written to
    • getPersistentBuffer

      public static PersistentBuffer getPersistentBuffer(long maximumCapacity) throws IOException
      Selects the most efficient temporary PersistentBuffer for the current machine and the provided maximum buffer size. The buffer will be backed by a temporary file that will be deleted on buffer close or JVM shutdown. The protection level will be ProtectionLevel.NONE. The order of preference is:
      1. MappedPersistentBuffer
      2. LargeMappedPersistentBuffer
      3. RandomAccessFileBuffer
      Parameters:
      maximumCapacity - The maximum size of data that may be stored in the buffer. To ensure no limits, use Long.MAX_VALUE.
      Throws:
      IOException
    • getPersistentBuffer

      public static PersistentBuffer getPersistentBuffer(RandomAccessFile raf, ProtectionLevel protectionLevel, long maximumCapacity) throws IOException
      Selects the most efficient PersistentBuffer for the current machine and the provided maximum buffer size. The order of preference is:
      1. MappedPersistentBuffer
      2. LargeMappedPersistentBuffer
      3. RandomAccessFileBuffer
      Parameters:
      maximumCapacity - The maximum size of data that may be stored in the buffer. If the random access file is larger than this value, the length of the file is used instead. To ensure no limits, use Long.MAX_VALUE.
      Throws:
      IOException
    • getSerializer

      public static <E> Serializer<E> getSerializer(Class<E> type)
      Selects the most efficient Serializer for the provided class.
    • getPersistentBlockBuffer

      public static PersistentBlockBuffer getPersistentBlockBuffer(Serializer<?> serializer, PersistentBuffer pbuffer, long additionalBlockSpace) throws IOException
      Gets the most efficient PersistentBlockBuffer for the provided provided Serializer. If using fixed record sizes, the size of the block buffer is rounded up to the nearest power of two, to help alignment with system page tables.
      Parameters:
      serializer - The Serializer that will be used to write to the blocks
      pbuffer - The PersistentBuffer that will be wrapped by the block buffer
      additionalBlockSpace - The maximum additional space needed beyond the space used by the serializer. This may be used for linked list pointers, for example.
      Throws:
      IOException