package f.y;

import f.t;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: compiled from: FileReadWrite.kt */
/* JADX INFO: loaded from: classes.dex */
public class h extends g {

    /* JADX INFO: compiled from: FileReadWrite.kt */
    static final class a extends f.z.d.l implements f.z.c.l<String, t> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ ArrayList<String> f3980b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(ArrayList<String> arrayList) {
            super(1);
            this.f3980b = arrayList;
        }

        public final void b(String str) {
            f.z.d.k.e(str, "it");
            this.f3980b.add(str);
        }

        @Override // f.z.c.l
        public /* bridge */ /* synthetic */ t c(String str) {
            b(str);
            return t.a;
        }
    }

    public static final void a(File file, byte[] bArr) throws IOException {
        f.z.d.k.e(file, "<this>");
        f.z.d.k.e(bArr, "array");
        FileOutputStream fileOutputStream = new FileOutputStream(file, true);
        try {
            fileOutputStream.write(bArr);
            t tVar = t.a;
            b.a(fileOutputStream, null);
        } finally {
        }
    }

    public static final void b(File file, String str, Charset charset) throws IOException {
        f.z.d.k.e(file, "<this>");
        f.z.d.k.e(str, "text");
        f.z.d.k.e(charset, "charset");
        byte[] bytes = str.getBytes(charset);
        f.z.d.k.d(bytes, "this as java.lang.String).getBytes(charset)");
        a(file, bytes);
    }

    public static /* synthetic */ void c(File file, String str, Charset charset, int i2, Object obj) throws IOException {
        if ((i2 & 2) != 0) {
            charset = f.e0.d.a;
        }
        b(file, str, charset);
    }

    public static final void d(File file, Charset charset, f.z.c.l<? super String, t> lVar) throws IOException {
        f.z.d.k.e(file, "<this>");
        f.z.d.k.e(charset, "charset");
        f.z.d.k.e(lVar, "action");
        m.c(new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)), lVar);
    }

    public static final List<String> e(File file, Charset charset) throws IOException {
        f.z.d.k.e(file, "<this>");
        f.z.d.k.e(charset, "charset");
        ArrayList arrayList = new ArrayList();
        d(file, charset, new a(arrayList));
        return arrayList;
    }

    public static /* synthetic */ List f(File file, Charset charset, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            charset = f.e0.d.a;
        }
        return e(file, charset);
    }

    public static final String g(File file, Charset charset) throws IOException {
        f.z.d.k.e(file, "<this>");
        f.z.d.k.e(charset, "charset");
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), charset);
        try {
            String strE = m.e(inputStreamReader);
            b.a(inputStreamReader, null);
            return strE;
        } finally {
        }
    }

    public static /* synthetic */ String h(File file, Charset charset, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            charset = f.e0.d.a;
        }
        return g(file, charset);
    }
}
