com.maxmind.geoip2

## Class DatabaseReader.Builder

- java.lang.Object
- - com.maxmind.geoip2.DatabaseReader.Builder

- Enclosing class:
    DatabaseReader

      public static final class DatabaseReader.Builder
      extends Object

  Constructs a Builder for the `DatabaseReader`. The file passed to it must be a valid GeoIP2 database file.

  `Builder` creates instances of `DatabaseReader` from values set by the methods.

  Only the values set in the `Builder` constructor are required.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) NodeCache` | `cache`
    `(package private) File` | `database`
    `(package private) List<String>` | `locales`
    `(package private) Reader.FileMode` | `mode`
    `(package private) InputStream` | `stream`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Builder(File database)`
    `Builder(InputStream stream)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DatabaseReader` | `build()`
    `DatabaseReader.Builder` | `fileMode(Reader.FileMode val)`
    `DatabaseReader.Builder` | `locales(List<String> val)`
    `DatabaseReader.Builder` | `withCache(NodeCache cache)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### cache

          NodeCache cache

    - #### database

          final File database

    - #### locales

          List<String> locales

    - #### mode

          Reader.FileMode mode

    - #### stream

          final InputStream stream

  - ### Constructor Detail

    - #### Builder

          public Builder(File database)

      Parameters:
        `database` - the GeoIP2 database file to use.

    - #### Builder

          public Builder(InputStream stream)

      Parameters:
        `stream` - the stream containing the GeoIP2 database to use.

  - ### Method Detail

    - #### build

          public DatabaseReader build()
                               throws IOException

      Returns:
        an instance of `DatabaseReader` created from the fields set on this builder.
      Throws:
        `IOException` - if there is an error reading the database

    - #### fileMode

          public DatabaseReader.Builder fileMode(Reader.FileMode val)

      Parameters:
        `val` - The file mode used to open the GeoIP2 database
      Returns:
        Builder object
      Throws:
        `IllegalArgumentException` - if you initialized the Builder with a URL, which uses `Reader.FileMode.MEMORY`, but you provided a different FileMode to this method.

    - #### locales

          public DatabaseReader.Builder locales(List<String> val)

      Parameters:
        `val` - List of locale codes to use in name property from most preferred to least preferred.
      Returns:
        Builder object

    - #### withCache

          public DatabaseReader.Builder withCache(NodeCache cache)

      Parameters:
        `cache` - backing cache instance
      Returns:
        Builder object