blob: 5301d3b11515a6694b32bb7dada161e598910922 [file] [log] [blame]
<html devsite="true">
<head>
<title>ReplaceFileCorruptionHandler</title>
{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div id="metadata-info-block">
<div id="source-link"><a href="https://cs.android.com/search?q=file:androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.+class:androidx.datastore.core.handlers.ReplaceFileCorruptionHandler&amp;ss=androidx/platform/frameworks/support" class="external">View Source</a></div>
</div>
<h1>ReplaceFileCorruptionHandler</h1>
<devsite-select id="platform" label="Select a platform"><select multiple="multiple"><option selected="selected" value="platform-Common/All">Common/All</option><option selected="selected" value="platform-Android/JVM">Android/JVM</option></select></devsite-select >
<devsite-filter select-el-container-id="platform">
<div>
<ul class="list" style="list-style: none; padding-left: 0">
<li>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All-->
<pre>class <a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html">ReplaceFileCorruptionHandler</a>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt;</pre>
</li>
</ul>
</div>
</devsite-filter >
<hr>
<p>A corruption handler that attempts to replace the on-disk data with data from produceNewData.</p>
<p>If the handler successfully replaces the data, the original exception is swallowed. If the handler encounters an exception when attempting to replace data, the new exception is added as a suppressed exception to the original exception and the original exception is thrown.</p>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="93%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html#ReplaceFileCorruptionHandler(kotlin.Function1)">ReplaceFileCorruptionHandler</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;produceNewData:&nbsp;(<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>) <span style="white-space: nowrap;">-&gt;</span> T<br>)</code></div>
</td>
<td>
<div class="kotlin-platform" data-title="Android/JVM"><span class="material-symbols-outlined">android</span></div>
<!--platform-Android/JVM--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
<div class="devsite-table-wrapper">
<devsite-filter select-el-container-id="platform">
<table class="fixed">
<colgroup>
<col width="35%">
<col width="58%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public functions</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>abstract&nbsp;suspend T</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html#handleCorruption(androidx.datastore.core.CorruptionException)">handleCorruption</a>(ex:&nbsp;<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>)</code></div>
<p>This function will be called by DataStore when it encounters corruption.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Common/All">Cmn</div>
<!--platform-Common/All--></td>
</tr>
<tr>
<td><code>open&nbsp;suspend T</code></td>
<td>
<div><code><a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html#handleCorruption(androidx.datastore.core.CorruptionException)">handleCorruption</a>(ex:&nbsp;<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>)</code></div>
<p>This function will be called by DataStore when it encounters corruption.</p>
</td>
<td>
<div class="kotlin-platform" data-title="Android/JVM"><span class="material-symbols-outlined">android</span></div>
<!--platform-Android/JVM--></td>
</tr>
</tbody>
</table>
</devsite-filter >
</div>
<devsite-filter select-el-container-id="platform">
<div class="list">
<h2>Public constructors</h2>
<div class="api-item"><a name="ReplaceFileCorruptionHandler-kotlin.Function1-"></a><a name="replacefilecorruptionhandler"></a>
<h3 class="api-name" id="ReplaceFileCorruptionHandler(kotlin.Function1)">ReplaceFileCorruptionHandler</h3>
<span class="kotlin-platform" data-title="Android/JVM"><span class="material-symbols-outlined">android</span></span>
<!--platform-Android/JVM-->
<pre class="api-signature no-pretty-print">&lt;T&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>?&gt; <a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html#ReplaceFileCorruptionHandler(kotlin.Function1)">ReplaceFileCorruptionHandler</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;produceNewData:&nbsp;(<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>) <span style="white-space: nowrap;">-&gt;</span> T<br>)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>produceNewData:&nbsp;(<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>) <span style="white-space: nowrap;">-&gt;</span> T</code></td>
<td>
<p>The provided callback returns the data to be written to disk. If the callback fails, nothing will be written to disk. Since the exception will be swallowed after writing the data, this is a good place to log the exception.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</devsite-filter >
<devsite-filter select-el-container-id="platform">
<div class="list">
<h2>Public functions</h2>
<div class="api-item"><a name="handleCorruption-androidx.datastore.core.CorruptionException-"></a><a name="handlecorruption"></a>
<h3 class="api-name" id="handleCorruption(androidx.datastore.core.CorruptionException)">handleCorruption</h3>
<span class="kotlin-platform" data-title="Common/All">Cmn</span>
<!--platform-Common/All-->
<pre class="api-signature no-pretty-print">abstract&nbsp;suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html#handleCorruption(androidx.datastore.core.CorruptionException)">handleCorruption</a>(ex:&nbsp;<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>):&nbsp;T</pre>
<p>This function will be called by DataStore when it encounters corruption. If the implementation of this function throws an exception, it will be propagated to the original call to DataStore. Otherwise, the returned data will be written to disk.</p>
<p>This function should not interact with any DataStore API - doing so can result in a deadlock.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>ex:&nbsp;<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a></code></td>
<td>
<p>is the exception encountered when attempting to deserialize data from disk.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>T</code></td>
<td>
<p>The value that DataStore should attempt to write to disk.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="handleCorruption-androidx.datastore.core.CorruptionException-"></a><a name="handlecorruption"></a>
<h3 class="api-name" id="handleCorruption(androidx.datastore.core.CorruptionException)">handleCorruption</h3>
<span class="kotlin-platform" data-title="Android/JVM"><span class="material-symbols-outlined">android</span></span>
<!--platform-Android/JVM-->
<pre class="api-signature no-pretty-print">open&nbsp;suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html#handleCorruption(androidx.datastore.core.CorruptionException)">handleCorruption</a>(ex:&nbsp;<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a>):&nbsp;T</pre>
<p>This function will be called by DataStore when it encounters corruption. If the implementation of this function throws an exception, it will be propagated to the original call to DataStore. Otherwise, the returned data will be written to disk.</p>
<p>This function should not interact with any DataStore API - doing so can result in a deadlock.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>ex:&nbsp;<a href="/reference/kotlin/androidx/datastore/core/CorruptionException.html">CorruptionException</a></code></td>
<td>
<p>is the exception encountered when attempting to deserialize data from disk.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>T</code></td>
<td>
<p>The value that DataStore should attempt to write to disk.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</devsite-filter >
</body>
</html>