what-the-bank/sources/okhttp3/internal/io/FileSystem.java

137 lines
4.6 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.internal.io;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import o.C14957gcv;
import o.C15160gio;
import o.C15164gis;
import o.InterfaceC15168giw;
import o.giD;
/* loaded from: classes.dex */
public interface FileSystem {
public static final Companion Companion = Companion.$$INSTANCE;
public static final FileSystem SYSTEM = new Companion.SystemFileSystem();
InterfaceC15168giw appendingSink(File file) throws FileNotFoundException;
void delete(File file) throws IOException;
void deleteContents(File file) throws IOException;
boolean exists(File file);
void rename(File file, File file2) throws IOException;
InterfaceC15168giw sink(File file) throws FileNotFoundException;
long size(File file);
giD source(File file) throws FileNotFoundException;
/* loaded from: classes.dex */
public static final class Companion {
static final Companion $$INSTANCE = new Companion();
private Companion() {
}
/* loaded from: classes.dex */
static final class SystemFileSystem implements FileSystem {
@Override // okhttp3.internal.io.FileSystem
public final giD source(File file) throws FileNotFoundException {
C14957gcv.e(file, "");
return C15160gio.a(file);
}
@Override // okhttp3.internal.io.FileSystem
public final InterfaceC15168giw sink(File file) throws FileNotFoundException {
InterfaceC15168giw e;
InterfaceC15168giw e2;
C14957gcv.e(file, "");
try {
e2 = C15164gis.e(file);
return e2;
} catch (FileNotFoundException unused) {
file.getParentFile().mkdirs();
e = C15164gis.e(file);
return e;
}
}
@Override // okhttp3.internal.io.FileSystem
public final InterfaceC15168giw appendingSink(File file) throws FileNotFoundException {
C14957gcv.e(file, "");
try {
return C15160gio.d(file);
} catch (FileNotFoundException unused) {
file.getParentFile().mkdirs();
return C15160gio.d(file);
}
}
@Override // okhttp3.internal.io.FileSystem
public final void delete(File file) throws IOException {
C14957gcv.e(file, "");
if (!file.delete() && file.exists()) {
throw new IOException(C14957gcv.c("failed to delete ", file));
}
}
@Override // okhttp3.internal.io.FileSystem
public final boolean exists(File file) {
C14957gcv.e(file, "");
return file.exists();
}
@Override // okhttp3.internal.io.FileSystem
public final long size(File file) {
C14957gcv.e(file, "");
return file.length();
}
@Override // okhttp3.internal.io.FileSystem
public final void rename(File file, File file2) throws IOException {
C14957gcv.e(file, "");
C14957gcv.e(file2, "");
delete(file2);
if (file.renameTo(file2)) {
return;
}
StringBuilder sb = new StringBuilder("failed to rename ");
sb.append(file);
sb.append(" to ");
sb.append(file2);
throw new IOException(sb.toString());
}
@Override // okhttp3.internal.io.FileSystem
public final void deleteContents(File file) throws IOException {
C14957gcv.e(file, "");
File[] listFiles = file.listFiles();
if (listFiles == null) {
throw new IOException(C14957gcv.c("not a readable directory: ", file));
}
int length = listFiles.length;
int i = 0;
while (i < length) {
File file2 = listFiles[i];
i++;
if (file2.isDirectory()) {
C14957gcv.c(file2, "");
deleteContents(file2);
}
if (!file2.delete()) {
throw new IOException(C14957gcv.c("failed to delete ", file2));
}
}
}
public final String toString() {
return "FileSystem.SYSTEM";
}
}
}
}