# GuavaDataStore.Builder

Artifact: [androidx.datastore:datastore-guava](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/guava/GuavaDataStore.kt+class:androidx.datastore.guava.GuavaDataStore.Builder) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

*** ** * ** ***

<br />

```
class GuavaDataStore.Builder<T : Any>
```

<br />

*** ** * ** ***

Builder class for a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore`.

## Summary

| ### Public constructors |
|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#Builder(androidx.datastore.core.Serializer,java.util.concurrent.Callable)(serializer: https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer<T>, produceFile: https://developer.android.com/reference/java/util/concurrent/Callable.html<https://developer.android.com/reference/java/io/File.html>)` |
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#Builder(android.content.Context,kotlin.String,androidx.datastore.core.Serializer)( context: https://developer.android.com/reference/android/content/Context.html, fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, serializer: https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer<T> )` Create a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder` with the `https://developer.android.com/reference/android/content/Context.html` and name from which to derive the `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` file. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#addDataMigration(androidx.datastore.core.DataMigration)(dataMigration: https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration<T>)` Add a DataMigration to the Datastore. |
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#build()()` Build the DataStore. |
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#enableMultiProcess()()` Flag used to signal the creation of a multi-process DataStore using a `https://developer.android.com/reference/kotlin/androidx/datastore/core/MultiProcessCoordinator`. |
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#setCorruptionHandler(androidx.datastore.core.handlers.ReplaceFileCorruptionHandler)( corruptionHandler: https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler<T> )` Sets the corruption handler to install into the DataStore. |
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#setExecutor(java.util.concurrent.Executor)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` used by the DataStore. |

## Public constructors

### Builder

```
<T : Any> Builder(serializer: Serializer<T>, produceFile: Callable<File>)
```

### Builder

```
<T : Any> Builder(
    context: Context,
    fileName: String,
    serializer: Serializer<T>
)
```

Create a `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder` with the `https://developer.android.com/reference/android/content/Context.html` and name from which to derive the `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` file. The file is generated by File(this.filesDir, "datastore/$fileName"). The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.

Either produceFile or context \& name must be set, but not both. This is enforced by the two constructors.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the `https://developer.android.com/reference/android/content/Context.html` from which we retrieve files directory. |
| `fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the filename relative to `https://developer.android.com/reference/android/content/Context.html#filesDir` that `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` acts on. The File is obtained from `https://developer.android.com/reference/kotlin/androidx/datastore/package-summary#(android.content.Context).dataStoreFile(kotlin.String)`. It is created in the "/datastore" subdirectory. |
| `serializer: https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer<T>` | the `https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer` for the type that this DataStore acts on. |

## Public functions

### addDataMigration

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

```
fun addDataMigration(dataMigration: DataMigration<T>): GuavaDataStore.Builder<T>
```

Add a DataMigration to the Datastore. Migrations are run in the order they are added.

| Parameters |
|---|---|
| `dataMigration: https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration<T>` | the migration to add |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | this |

### build

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

```
fun build(): GuavaDataStore<T>
```

Build the DataStore.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore<T>` | the DataStore with the provided parameters |

### enableMultiProcess

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

```
fun enableMultiProcess(): GuavaDataStore.Builder<T>
```

Flag used to signal the creation of a multi-process DataStore using a `https://developer.android.com/reference/kotlin/androidx/datastore/core/MultiProcessCoordinator`.

By default, the builder sets up a `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` intended for single-application use. It prioritizes speed and is created using `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStoreFactory`. However, if you anticipate any scenario where different parts of your system (even if they are just reading data) might access the `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` at the same time from separate processes, the `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder#enableMultiProcess()` flag must be set to `true`. This ensures a `https://developer.android.com/reference/kotlin/androidx/datastore/core/MultiProcessDataStoreFactory` is used, providing the necessary safeguards for concurrent access across multiple processes.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | this |

### setCorruptionHandler

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

```
fun setCorruptionHandler(
    corruptionHandler: ReplaceFileCorruptionHandler<T>
): GuavaDataStore.Builder<T>
```

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

| Parameters |
|---|---|
| `corruptionHandler: https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler<T>` | the handler to invoke when there is a file corruption |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | this |

### setExecutor

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

```
fun setExecutor(executor: Executor): GuavaDataStore.Builder<T>
```

Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` used by the DataStore.

This parameter is optional and defaults to `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the executor to be used by `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/guava/GuavaDataStore.Builder<T>` | this |