granularity level: instruction
.class public Landroidx/core/util/AtomicFile;
.super Ljava/lang/Object;
.source "AtomicFile.java"
.field private final mBackupName:Ljava/io/File;
.field private final mBaseName:Ljava/io/File;
.method public constructor <init>(Ljava/io/File;)V
.locals 2
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
iput-object p1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
new-instance v0, Ljava/io/File;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
invoke-virtual {p1}, Ljava/io/File;->getPath()Ljava/lang/String;
move-result-object p1
invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
const-string p1, ".bak"
invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object p1
invoke-direct {v0, p1}, Ljava/io/File;-><init>(Ljava/lang/String;)V
iput-object v0, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
return-void
.end method
.method private static sync(Ljava/io/FileOutputStream;)Z
.locals 0
:try_start_0
invoke-virtual {p0}, Ljava/io/FileOutputStream;->getFD()Ljava/io/FileDescriptor;
move-result-object p0
invoke-virtual {p0}, Ljava/io/FileDescriptor;->sync()V
:try_end_0
.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
const/4 p0, 0x1
return p0
:catch_0
const/4 p0, 0x0
return p0
.end method
.method public delete()V
.locals 1
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->delete()Z
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->delete()Z
return-void
.end method
.method public failWrite(Ljava/io/FileOutputStream;)V
.locals 2
if-eqz p1, :cond_0
invoke-static {p1}, Landroidx/core/util/AtomicFile;->sync(Ljava/io/FileOutputStream;)Z
:try_start_0
invoke-virtual {p1}, Ljava/io/FileOutputStream;->close()V
iget-object p1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {p1}, Ljava/io/File;->delete()Z
iget-object p1, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {p1, v0}, Ljava/io/File;->renameTo(Ljava/io/File;)Z
:try_end_0
.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
goto :goto_0
:catch_0
move-exception p1
const-string v0, "AtomicFile"
const-string v1, "failWrite: Got exception:"
invoke-static {v0, v1, p1}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
:goto_0
:cond_0
return-void
.end method
.method public finishWrite(Ljava/io/FileOutputStream;)V
.locals 2
if-eqz p1, :cond_0
invoke-static {p1}, Landroidx/core/util/AtomicFile;->sync(Ljava/io/FileOutputStream;)Z
:try_start_0
invoke-virtual {p1}, Ljava/io/FileOutputStream;->close()V
iget-object p1, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
invoke-virtual {p1}, Ljava/io/File;->delete()Z
:try_end_0
.catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
goto :goto_0
:catch_0
move-exception p1
const-string v0, "AtomicFile"
const-string v1, "finishWrite: Got exception:"
invoke-static {v0, v1, p1}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
:goto_0
:cond_0
return-void
.end method
.method public getBaseFile()Ljava/io/File;
.locals 1
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
return-object v0
.end method
.method public openRead()Ljava/io/FileInputStream;
.locals 2
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/FileNotFoundException;
}
.end annotation
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->exists()Z
move-result v0
if-eqz v0, :cond_0
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->delete()Z
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0, v1}, Ljava/io/File;->renameTo(Ljava/io/File;)Z
:cond_0
new-instance v0, Ljava/io/FileInputStream;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-direct {v0, v1}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V
return-object v0
.end method
.method public readFully()[B
.locals 6
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
invoke-virtual {p0}, Landroidx/core/util/AtomicFile;->openRead()Ljava/io/FileInputStream;
move-result-object v0
:try_start_0
invoke-virtual {v0}, Ljava/io/FileInputStream;->available()I
move-result v1
new-array v1, v1, [B
const/4 v2, 0x0
const/4 v3, 0x0
:goto_0
:cond_0
array-length v4, v1
sub-int/2addr v4, v3
invoke-virtual {v0, v1, v3, v4}, Ljava/io/FileInputStream;->read([BII)I
move-result v4
:try_end_0
.catchall {:try_start_0 .. :try_end_0} :catchall_0
if-gtz v4, :cond_1
invoke-virtual {v0}, Ljava/io/FileInputStream;->close()V
return-object v1
:cond_1
add-int/2addr v3, v4
:try_start_1
invoke-virtual {v0}, Ljava/io/FileInputStream;->available()I
move-result v4
array-length v5, v1
sub-int/2addr v5, v3
if-le v4, v5, :cond_0
add-int/2addr v4, v3
new-array v4, v4, [B
invoke-static {v1, v2, v4, v2, v3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
:try_end_1
.catchall {:try_start_1 .. :try_end_1} :catchall_0
move-object v1, v4
goto :goto_0
:catchall_0
move-exception v1
invoke-virtual {v0}, Ljava/io/FileInputStream;->close()V
throw v1
.end method
.method public startWrite()Ljava/io/FileOutputStream;
.locals 3
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->exists()Z
move-result v0
if-eqz v0, :cond_1
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->exists()Z
move-result v0
if-nez v0, :cond_0
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
invoke-virtual {v0, v1}, Ljava/io/File;->renameTo(Ljava/io/File;)Z
move-result v0
if-nez v0, :cond_1
new-instance v0, Ljava/lang/StringBuilder;
invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
const-string v1, "Couldn\'t rename file "
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
const-string v1, " to backup file "
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBackupName:Ljava/io/File;
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v0
const-string v1, "AtomicFile"
invoke-static {v1, v0}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I
goto :goto_0
:cond_0
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->delete()Z
:goto_0
:try_start_0
:cond_1
new-instance v0, Ljava/io/FileOutputStream;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-direct {v0, v1}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V
:try_end_0
.catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0
goto :goto_1
:catch_0
nop
iget-object v0, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v0}, Ljava/io/File;->getParentFile()Ljava/io/File;
move-result-object v0
invoke-virtual {v0}, Ljava/io/File;->mkdirs()Z
move-result v0
if-eqz v0, :cond_2
:try_start_1
new-instance v0, Ljava/io/FileOutputStream;
iget-object v1, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-direct {v0, v1}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V
:try_end_1
.catch Ljava/io/FileNotFoundException; {:try_start_1 .. :try_end_1} :catch_1
:goto_1
return-object v0
:catch_1
new-instance v0, Ljava/io/IOException;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
const-string v2, "Couldn\'t create "
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
iget-object v2, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v1
invoke-direct {v0, v1}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
throw v0
:cond_2
new-instance v0, Ljava/io/IOException;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
const-string v2, "Couldn\'t create directory "
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
iget-object v2, p0, Landroidx/core/util/AtomicFile;->mBaseName:Ljava/io/File;
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v1
invoke-direct {v0, v1}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
throw v0
.end method