package i1;

import e1.AbstractC0453a;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Hashtable;
import k1.Y;
import l1.C0622e;

/* JADX INFO: renamed from: i1.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0547a {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static int f4402d;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final String f4399a = AbstractC0453a.g("jcifs.netbios.lmhosts");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Hashtable f4400b = new Hashtable();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static long f4401c = 1;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static C0622e f4403e = C0622e.a();

    static synchronized g a(C0548b c0548b) {
        g gVar;
        gVar = null;
        try {
            try {
                String str = f4399a;
                if (str != null) {
                    File file = new File(str);
                    long jLastModified = file.lastModified();
                    if (jLastModified > f4401c) {
                        f4401c = jLastModified;
                        f4400b.clear();
                        f4402d = 0;
                        c(new FileReader(file));
                    }
                    gVar = (g) f4400b.get(c0548b);
                }
            } catch (FileNotFoundException e2) {
                if (C0622e.f5384g > 1) {
                    f4403e.println("lmhosts file: " + f4399a);
                    e2.printStackTrace(f4403e);
                }
            } catch (IOException e3) {
                if (C0622e.f5384g > 0) {
                    e3.printStackTrace(f4403e);
                }
            }
        } catch (Throwable th) {
            throw th;
        }
        return gVar;
    }

    public static synchronized g b(String str) {
        return a(new C0548b(str, 32, null));
    }

    static void c(Reader reader) throws IOException {
        String line;
        int i2;
        BufferedReader bufferedReader = new BufferedReader(reader);
        while (true) {
            String line2 = bufferedReader.readLine();
            if (line2 == null) {
                return;
            }
            String strTrim = line2.toUpperCase().trim();
            if (strTrim.length() != 0) {
                if (strTrim.charAt(0) == '#') {
                    if (strTrim.startsWith("#INCLUDE ")) {
                        String str = "smb:" + strTrim.substring(strTrim.indexOf(92)).replace('\\', '/');
                        if (f4402d > 0) {
                            try {
                                c(new InputStreamReader(new Y(str)));
                                f4402d--;
                                do {
                                    line = bufferedReader.readLine();
                                    if (line != null) {
                                    }
                                } while (!line.toUpperCase().trim().startsWith("#END_ALTERNATE"));
                            } catch (IOException e2) {
                                f4403e.println("lmhosts URL: " + str);
                                e2.printStackTrace(f4403e);
                            }
                        } else {
                            c(new InputStreamReader(new Y(str)));
                        }
                    } else if (strTrim.startsWith("#BEGIN_ALTERNATE")) {
                        f4402d++;
                    } else if (strTrim.startsWith("#END_ALTERNATE") && (i2 = f4402d) > 0) {
                        f4402d = i2 - 1;
                        throw new IOException("no lmhosts alternate includes loaded");
                    }
                } else if (Character.isDigit(strTrim.charAt(0))) {
                    char[] charArray = strTrim.toCharArray();
                    int i3 = 0;
                    int i4 = 0;
                    char c2 = '.';
                    while (i3 < charArray.length && c2 == '.') {
                        int i5 = 0;
                        while (i3 < charArray.length && (c2 = charArray[i3]) >= '0' && c2 <= '9') {
                            i5 = ((i5 * 10) + c2) - 48;
                            i3++;
                        }
                        i4 = (i4 << 8) + i5;
                        i3++;
                    }
                    while (i3 < charArray.length && Character.isWhitespace(charArray[i3])) {
                        i3++;
                    }
                    int i6 = i3;
                    while (i6 < charArray.length && !Character.isWhitespace(charArray[i6])) {
                        i6++;
                    }
                    C0548b c0548b = new C0548b(strTrim.substring(i3, i6), 32, null);
                    f4400b.put(c0548b, new g(c0548b, i4, false, 0, false, false, true, true, g.f4466t));
                }
            }
        }
    }
}
