Files
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

114 lines
3.7 KiB
Java

package com.mbridge.msdk.playercommon.exoplayer2.util;
import android.util.Log;
import androidx.annotation.NonNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/* loaded from: classes4.dex */
public final class AtomicFile {
private static final String TAG = "AtomicFile";
private final File backupName;
private final File baseName;
public AtomicFile(File file) {
this.baseName = file;
this.backupName = new File(file.getPath() + ".bak");
}
public final void delete() {
this.baseName.delete();
this.backupName.delete();
}
public final OutputStream startWrite() throws IOException {
if (this.baseName.exists()) {
if (!this.backupName.exists()) {
if (!this.baseName.renameTo(this.backupName)) {
Log.w(TAG, "Couldn't rename file " + this.baseName + " to backup file " + this.backupName);
}
} else {
this.baseName.delete();
}
}
try {
return new AtomicFileOutputStream(this.baseName);
} catch (FileNotFoundException e) {
if (!this.baseName.getParentFile().mkdirs()) {
throw new IOException("Couldn't create directory " + this.baseName, e);
}
try {
return new AtomicFileOutputStream(this.baseName);
} catch (FileNotFoundException e2) {
throw new IOException("Couldn't create " + this.baseName, e2);
}
}
}
public final void endWrite(OutputStream outputStream) throws IOException {
outputStream.close();
this.backupName.delete();
}
public final InputStream openRead() throws FileNotFoundException {
restoreBackup();
return new FileInputStream(this.baseName);
}
private void restoreBackup() {
if (this.backupName.exists()) {
this.baseName.delete();
this.backupName.renameTo(this.baseName);
}
}
public static final class AtomicFileOutputStream extends OutputStream {
private boolean closed = false;
private final FileOutputStream fileOutputStream;
public AtomicFileOutputStream(File file) throws FileNotFoundException {
this.fileOutputStream = new FileOutputStream(file);
}
@Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
if (this.closed) {
return;
}
this.closed = true;
flush();
try {
this.fileOutputStream.getFD().sync();
} catch (IOException e) {
Log.w(AtomicFile.TAG, "Failed to sync file descriptor:", e);
}
this.fileOutputStream.close();
}
@Override // java.io.OutputStream, java.io.Flushable
public final void flush() throws IOException {
this.fileOutputStream.flush();
}
@Override // java.io.OutputStream
public final void write(int i) throws IOException {
this.fileOutputStream.write(i);
}
@Override // java.io.OutputStream
public final void write(@NonNull byte[] bArr) throws IOException {
this.fileOutputStream.write(bArr);
}
@Override // java.io.OutputStream
public final void write(@NonNull byte[] bArr, int i, int i2) throws IOException {
this.fileOutputStream.write(bArr, i, i2);
}
}
}