package okhttp3.internal.io;

import c.q.d.g;
import c.q.d.j;
import d.a0;
import d.p;
import d.y;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/* JADX INFO: compiled from: FileSystem.kt */
/* JADX INFO: loaded from: classes.dex */
public interface FileSystem {
    public static final Companion Companion = new Companion(null);
    public static final FileSystem SYSTEM = new FileSystem() { // from class: okhttp3.internal.io.FileSystem$Companion$SYSTEM$1
        @Override // okhttp3.internal.io.FileSystem
        public y appendingSink(File file) throws FileNotFoundException {
            j.c(file, "file");
            try {
                return p.a(file);
            } catch (FileNotFoundException unused) {
                file.getParentFile().mkdirs();
                return p.a(file);
            }
        }

        @Override // okhttp3.internal.io.FileSystem
        public void delete(File file) throws IOException {
            j.c(file, "file");
            if (file.delete() || !file.exists()) {
                return;
            }
            throw new IOException("failed to delete " + file);
        }

        @Override // okhttp3.internal.io.FileSystem
        public void deleteContents(File file) throws IOException {
            j.c(file, "directory");
            File[] fileArrListFiles = file.listFiles();
            if (fileArrListFiles == null) {
                throw new IOException("not a readable directory: " + file);
            }
            for (File file2 : fileArrListFiles) {
                j.b(file2, "file");
                if (file2.isDirectory()) {
                    deleteContents(file2);
                }
                if (!file2.delete()) {
                    throw new IOException("failed to delete " + file2);
                }
            }
        }

        @Override // okhttp3.internal.io.FileSystem
        public boolean exists(File file) {
            j.c(file, "file");
            return file.exists();
        }

        @Override // okhttp3.internal.io.FileSystem
        public void rename(File file, File file2) throws IOException {
            j.c(file, "from");
            j.c(file2, "to");
            delete(file2);
            if (file.renameTo(file2)) {
                return;
            }
            throw new IOException("failed to rename " + file + " to " + file2);
        }

        @Override // okhttp3.internal.io.FileSystem
        public y sink(File file) throws FileNotFoundException {
            j.c(file, "file");
            try {
                return p.i(file, false, 1, null);
            } catch (FileNotFoundException unused) {
                file.getParentFile().mkdirs();
                return p.i(file, false, 1, null);
            }
        }

        @Override // okhttp3.internal.io.FileSystem
        public long size(File file) {
            j.c(file, "file");
            return file.length();
        }

        @Override // okhttp3.internal.io.FileSystem
        public a0 source(File file) throws FileNotFoundException {
            j.c(file, "file");
            return p.j(file);
        }
    };

    /* JADX INFO: compiled from: FileSystem.kt */
    public static final class Companion {
        static final /* synthetic */ Companion $$INSTANCE = null;

        private Companion() {
        }

        public /* synthetic */ Companion(g gVar) {
            this();
        }
    }

    y 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;

    y sink(File file) throws FileNotFoundException;

    long size(File file);

    a0 source(File file) throws FileNotFoundException;
}
