java.lang.Object
com.maxmind.db.BufferHolder

final class BufferHolderextends Object
Holds a ByteBuffer for MaxMind database access. Provides thread-safe access to database data either memory-mapped or loaded into memory.
  • Field Details

    • buffer

      private final ByteBuffer buffer
      The buffer backing the reads. Do not pass it outside this class - doing so removes the thread safety.
  • Constructor Details

    • BufferHolder

      BufferHolder(File database, Reader.FileMode mode) throws IOException
      Create a BufferHolder from a database file.
      Parameters:
      database - the database file
      mode - the file mode
      Throws:
      IOException - if the file cannot be read
    • BufferHolder

      BufferHolder(InputStream stream) throws IOException
      Construct a ThreadBuffer from the provided URL.
      Parameters:
      stream - the source of my bytes.
      Throws:
      IOException - if unable to read from your source.
      NullPointerException - if you provide a NULL InputStream
    • BufferHolder

      BufferHolder(ByteBuffer buffer)
      Create a BufferHolder from a ByteBuffer. This is just to ease unit testing.
      Parameters:
      buffer - the byte buffer
  • Method Details

    • get

      ByteBuffer get()
      Returns a duplicate of the underlying ByteBuffer. The returned ByteBuffer should not be shared between threads.
      Returns:
      a duplicate of the underlying ByteBuffer