导航菜单

页面标题

页面副标题

BAM Crawford v6.14.1 - f.java 源代码

正在查看: BAM Crawford v6.14.1 应用的 f.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package io.sentry.cache;

import io.sentry.ILogger;
import io.sentry.UncaughtExceptionHandlerIntegration;
import io.sentry.a4;
import io.sentry.c0;
import io.sentry.f6;
import io.sentry.i5;
import io.sentry.j5;
import io.sentry.s5;
import io.sentry.transport.s;
import io.sentry.x3;
import io.sentry.x4;
import io.sentry.y0;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class f extends c implements g {
    private final CountDownLatch u;
    private final Map v;

    public f(s5 s5Var, String str, int i) {
        super(s5Var, str, i);
        this.v = new WeakHashMap();
        this.u = new CountDownLatch(1);
    }

    public static File C(String str) {
        return new File(str, "session.json");
    }

    private synchronized File E(a4 a4Var) {
        String str;
        if (this.v.containsKey(a4Var)) {
            str = (String) this.v.get(a4Var);
        } else {
            String str2 = UUID.randomUUID() + ".envelope";
            this.v.put(a4Var, str2);
            str = str2;
        }
        return new File(this.r.getAbsolutePath(), str);
    }

    public static File F(String str) {
        return new File(str, "previous_session.json");
    }

    public static boolean G(File file, String str) {
        return str.endsWith(".envelope");
    }

    private void H(c0 c0Var) {
        Date date;
        Object g = io.sentry.util.j.g(c0Var);
        if (g instanceof io.sentry.hints.a) {
            File F = F(this.r.getAbsolutePath());
            if (!F.exists()) {
                this.p.getLogger().c(j5.DEBUG, "No previous session file to end.", new Object[0]);
                return;
            }
            ILogger logger = this.p.getLogger();
            j5 j5Var = j5.WARNING;
            logger.c(j5Var, "Previous session is not ended, we'd need to end it.", new Object[0]);
            try {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(F), c.t));
                try {
                    f6 f6Var = (f6) ((y0) this.q.a()).c(bufferedReader, f6.class);
                    if (f6Var != null) {
                        io.sentry.hints.a aVar = (io.sentry.hints.a) g;
                        Long c = aVar.c();
                        if (c != null) {
                            date = io.sentry.j.d(c.longValue());
                            Date k = f6Var.k();
                            if (k == null || date.before(k)) {
                                this.p.getLogger().c(j5Var, "Abnormal exit happened before previous session start, not ending the session.", new Object[0]);
                                bufferedReader.close();
                                return;
                            }
                        } else {
                            date = null;
                        }
                        f6Var.q(f6.b.Abnormal, null, true, aVar.g());
                        f6Var.d(date);
                        N(F, f6Var);
                    }
                    bufferedReader.close();
                } finally {
                }
            } catch (Throwable th2) {
                this.p.getLogger().b(j5.ERROR, "Error processing previous session.", th2);
            }
        }
    }

    private void J(File file, a4 a4Var) {
        Iterable c = a4Var.c();
        if (!c.iterator().hasNext()) {
            this.p.getLogger().c(j5.INFO, "Current envelope %s is empty", file.getAbsolutePath());
            return;
        }
        x4 x4Var = (x4) c.iterator().next();
        if (!i5.Session.equals(x4Var.G().b())) {
            this.p.getLogger().c(j5.INFO, "Current envelope has a different envelope type %s", x4Var.G().b());
            return;
        }
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(x4Var.E()), c.t));
            try {
                f6 f6Var = (f6) ((y0) this.q.a()).c(bufferedReader, f6.class);
                if (f6Var == null) {
                    this.p.getLogger().c(j5.ERROR, "Item of type %s returned null by the parser.", x4Var.G().b());
                } else {
                    N(file, f6Var);
                }
                bufferedReader.close();
            } finally {
            }
        } catch (Throwable th2) {
            this.p.getLogger().b(j5.ERROR, "Item failed to process.", th2);
        }
    }

    private void L() {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(new File(this.p.getCacheDirPath(), "last_crash"));
            try {
                fileOutputStream.write(io.sentry.j.g(io.sentry.j.c()).getBytes(c.t));
                fileOutputStream.flush();
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th2) {
            this.p.getLogger().b(j5.ERROR, "Error writing the crash marker file to the disk", th2);
        }
    }

    private void M(File file, a4 a4Var) {
        if (file.exists()) {
            this.p.getLogger().c(j5.DEBUG, "Overwriting envelope to offline storage: %s", file.getAbsolutePath());
            if (!file.delete()) {
                this.p.getLogger().c(j5.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                ((y0) this.q.a()).b(a4Var, fileOutputStream);
                fileOutputStream.close();
            } finally {
            }
        } catch (Throwable th2) {
            this.p.getLogger().a(j5.ERROR, th2, "Error writing Envelope %s to offline storage", file.getAbsolutePath());
        }
    }

    private void N(File file, f6 f6Var) {
        if (file.exists()) {
            this.p.getLogger().c(j5.DEBUG, "Overwriting session to offline storage: %s", f6Var.j());
            if (!file.delete()) {
                this.p.getLogger().c(j5.ERROR, "Failed to delete: %s", file.getAbsolutePath());
            }
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            try {
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, c.t));
                try {
                    ((y0) this.q.a()).a(f6Var, bufferedWriter);
                    bufferedWriter.close();
                    fileOutputStream.close();
                } finally {
                }
            } finally {
            }
        } catch (Throwable th2) {
            this.p.getLogger().a(j5.ERROR, th2, "Error writing Session to offline storage: %s", f6Var.j());
        }
    }

    private File[] x() {
        File[] listFiles;
        return (!f() || (listFiles = this.r.listFiles(new FilenameFilter() {
            @Override
            public final boolean accept(File file, String str) {
                boolean G;
                G = f.G(file, str);
                return G;
            }
        })) == null) ? new File[0] : listFiles;
    }

    public static g y(s5 s5Var) {
        String cacheDirPath = s5Var.getCacheDirPath();
        int maxCacheItems = s5Var.getMaxCacheItems();
        if (cacheDirPath != null) {
            return new f(s5Var, cacheDirPath, maxCacheItems);
        }
        s5Var.getLogger().c(j5.WARNING, "cacheDirPath is null, returning NoOpEnvelopeCache", new Object[0]);
        return s.a();
    }

    public void B() {
        this.u.countDown();
    }

    @Override
    public void D(a4 a4Var) {
        io.sentry.util.q.c(a4Var, "Envelope is required.");
        File E = E(a4Var);
        if (!E.exists()) {
            this.p.getLogger().c(j5.DEBUG, "Envelope was not cached: %s", E.getAbsolutePath());
            return;
        }
        this.p.getLogger().c(j5.DEBUG, "Discarding envelope from cache: %s", E.getAbsolutePath());
        if (E.delete()) {
            return;
        }
        this.p.getLogger().c(j5.ERROR, "Failed to delete envelope: %s", E.getAbsolutePath());
    }

    public boolean K() {
        try {
            return this.u.await(this.p.getSessionFlushTimeoutMillis(), TimeUnit.MILLISECONDS);
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
            this.p.getLogger().c(j5.DEBUG, "Timed out waiting for previous session to flush.", new Object[0]);
            return false;
        }
    }

    public void f0(a4 a4Var, c0 c0Var) {
        io.sentry.util.q.c(a4Var, "Envelope is required.");
        s(x());
        File C = C(this.r.getAbsolutePath());
        File F = F(this.r.getAbsolutePath());
        if (io.sentry.util.j.h(c0Var, io.sentry.hints.l.class) && !C.delete()) {
            this.p.getLogger().c(j5.WARNING, "Current envelope doesn't exist.", new Object[0]);
        }
        if (io.sentry.util.j.h(c0Var, io.sentry.hints.a.class)) {
            H(c0Var);
        }
        if (io.sentry.util.j.h(c0Var, io.sentry.hints.n.class)) {
            if (C.exists()) {
                this.p.getLogger().c(j5.WARNING, "Current session is not ended, we'd need to end it.", new Object[0]);
                try {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(C), c.t));
                    try {
                        f6 f6Var = (f6) ((y0) this.q.a()).c(bufferedReader, f6.class);
                        if (f6Var != null) {
                            N(F, f6Var);
                        }
                        bufferedReader.close();
                    } finally {
                    }
                } catch (Throwable th2) {
                    this.p.getLogger().b(j5.ERROR, "Error processing session.", th2);
                }
            }
            J(C, a4Var);
            boolean exists = new File(this.p.getCacheDirPath(), ".sentry-native/last_crash").exists();
            if (!exists) {
                File file = new File(this.p.getCacheDirPath(), "last_crash");
                if (file.exists()) {
                    this.p.getLogger().c(j5.INFO, "Crash marker file exists, crashedLastRun will return true.", new Object[0]);
                    if (!file.delete()) {
                        this.p.getLogger().c(j5.ERROR, "Failed to delete the crash marker file. %s.", file.getAbsolutePath());
                    }
                    exists = true;
                }
            }
            x3.a().c(exists);
            B();
        }
        File E = E(a4Var);
        if (E.exists()) {
            this.p.getLogger().c(j5.WARNING, "Not adding Envelope to offline storage because it already exists: %s", E.getAbsolutePath());
            return;
        }
        this.p.getLogger().c(j5.DEBUG, "Adding Envelope to offline storage: %s", E.getAbsolutePath());
        M(E, a4Var);
        if (io.sentry.util.j.h(c0Var, UncaughtExceptionHandlerIntegration.a.class)) {
            L();
        }
    }

    @Override
    public Iterator iterator() {
        File[] x = x();
        ArrayList arrayList = new ArrayList(x.length);
        for (File file : x) {
            try {
                BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
                try {
                    arrayList.add(((y0) this.q.a()).d(bufferedInputStream));
                    bufferedInputStream.close();
                } catch (Throwable th2) {
                    try {
                        bufferedInputStream.close();
                    } catch (Throwable th3) {
                        th2.addSuppressed(th3);
                    }
                    throw th2;
                }
            } catch (FileNotFoundException unused) {
                this.p.getLogger().c(j5.DEBUG, "Envelope file '%s' disappeared while converting all cached files to envelopes.", file.getAbsolutePath());
            } catch (IOException e) {
                this.p.getLogger().b(j5.ERROR, String.format("Error while reading cached envelope from file %s", file.getAbsolutePath()), e);
            }
        }
        return arrayList.iterator();
    }
}