package K1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/* JADX INFO: loaded from: classes2.dex */
public class s {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final i[] f1274e = new i[0];

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private List f1275a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private ListIterator f1276b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final j f1277c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final boolean f1278d;

    s(j jVar, f fVar) {
        LinkedList linkedList = new LinkedList();
        this.f1275a = linkedList;
        this.f1276b = linkedList.listIterator();
        this.f1277c = jVar;
        if (fVar != null) {
            this.f1278d = fVar.h();
        } else {
            this.f1278d = false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ i e(String str) {
        i iVarC = this.f1277c.c(str);
        return (iVarC == null && this.f1278d) ? new i(str) : iVarC;
    }

    private void f(InputStream inputStream, String str) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, N1.a.a(str)));
        try {
            String strA = this.f1277c.a(bufferedReader);
            while (strA != null) {
                this.f1275a.add(strA);
                strA = this.f1277c.a(bufferedReader);
            }
            bufferedReader.close();
        } catch (Throwable th) {
            try {
                bufferedReader.close();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
    }

    public List b(final l lVar) {
        Stream map = this.f1275a.stream().map(new Function() { // from class: K1.q
            @Override // java.util.function.Function
            public final Object apply(Object obj) {
                return this.f1272a.e((String) obj);
            }
        });
        Objects.requireNonNull(lVar);
        return (List) map.filter(new Predicate() { // from class: K1.r
            @Override // java.util.function.Predicate
            public final boolean test(Object obj) {
                return lVar.a((i) obj);
            }
        }).collect(Collectors.toList());
    }

    public i[] c() {
        return d(p.f1270b);
    }

    public i[] d(l lVar) {
        return (i[]) b(lVar).toArray(f1274e);
    }

    public void g(InputStream inputStream, String str) throws IOException {
        this.f1275a = new LinkedList();
        f(inputStream, str);
        this.f1277c.b(this.f1275a);
        h();
    }

    public void h() {
        this.f1276b = this.f1275a.listIterator();
    }
}
