导航菜单

页面标题

页面副标题

零界绘 v1.0.2 - l.java 源代码

正在查看: 零界绘 v1.0.2 应用的 l.java JAVA 源代码文件

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


package com.anythink.dlopt.common.a;

import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.text.TextUtils;
import android.util.SparseIntArray;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.StringWriter;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.http.conn.ConnectTimeoutException;

public class l {
    public static final String a = "l";
    public String b;
    public String c;
    public String d;

    public boolean f1665e;

    public int f1666f;
    public long g;
    public long h;
    public int i;
    public g j;
    public k k;
    public ExecutorService l;
    public f m;

    public static class a {
        public final l a = new l(0);

        public final a a(String str) {
            this.a.b = str;
            return this;
        }

        public final a b(String str) {
            this.a.c = str;
            return this;
        }

        public final a c(String str) {
            this.a.d = str;
            return this;
        }

        public final a a(boolean z) {
            this.a.f1665e = z;
            return this;
        }

        public final a b() {
            l.i(this.a);
            return this;
        }

        public final l c() {
            return this.a;
        }

        public final a a(int i) {
            this.a.f1666f = i;
            return this;
        }

        public final a a(long j) {
            this.a.g = j;
            return this;
        }

        public final a a(k kVar) {
            this.a.k = kVar;
            return this;
        }

        public final a a(ExecutorService executorService) {
            this.a.l = executorService;
            return this;
        }

        public final a a() {
            l.h(this.a);
            return this;
        }
    }

    public static abstract class b implements Runnable {
        @Override
        public void run() {
            Thread.currentThread().setName(l.f());
        }
    }

    public enum c {
        HTTP_STATUS,
        HTTP_TIMEOUT,
        EXCEPTION,
        CONNECT_EXCEPTION;

        public static c[] a() {
            return new c[]{HTTP_STATUS, HTTP_TIMEOUT, EXCEPTION, CONNECT_EXCEPTION};
        }
    }

    public static class d extends b {
        public static final int a = 1048576;
        public final int b;
        public final String c;
        public final String d;

        public final String f1668e;

        public long f1669f;
        public final int g;
        public final int h;
        public final int i;
        public final e j;
        public final l k;

        public d(int i, String str, String str2, String str3, long j, int i2, int i3, int i4, e eVar, l lVar, byte b) {
            this(i, str, str2, str3, j, i2, i3, i4, eVar, lVar);
        }

        private boolean a() {
            if (this.k.d() == g.STOP) {
                this.j.b(this.b);
                return true;
            }
            if (this.k.d() != g.PAUSE) {
                return false;
            }
            this.j.a(this.b);
            return true;
        }

        @Override
        public final void run() {
            int i;
            HttpURLConnection httpURLConnection;
            super.run();
            if (this.k == null || this.j == null) {
                return;
            }
            int i2 = this.h;
            if ((i2 > 0 && this.g == i2) || ((i = this.i) > 0 && this.h == i)) {
                String unused = l.a;
                this.j.a(this.b, this.i);
                this.j.c(this.b);
                return;
            }
            this.j.a(this.b, this.i);
            HttpURLConnection httpURLConnection2 = null;
            try {
                try {
                    httpURLConnection = (HttpURLConnection) new URL(this.c).openConnection();
                } catch (Throwable th) {
                    if (0 != 0) {
                        try {
                            httpURLConnection2.disconnect();
                        } catch (Throwable th2) {
                            String unused2 = l.a;
                            new StringBuilder("close failed: ").append(th2.getMessage());
                        }
                    }
                    throw th;
                }
            } catch (OutOfMemoryError e2) {
                e = e2;
            } catch (StackOverflowError e3) {
                e = e3;
            } catch (Error e4) {
                e = e4;
            } catch (ConnectException e5) {
                e = e5;
            } catch (SocketTimeoutException e6) {
                e = e6;
            } catch (ConnectTimeoutException e7) {
                e = e7;
            } catch (Exception e8) {
                e = e8;
            } catch (Throwable th3) {
                th = th3;
            }
            try {
                httpURLConnection.setInstanceFollowRedirects(false);
                if (TextUtils.isEmpty(this.f1668e)) {
                    httpURLConnection.addRequestProperty(com.anythink.basead.l.a.b, this.f1668e);
                }
                String str = "bytes=" + this.g + "-";
                if (this.h > 0) {
                    str = "bytes=" + this.g + "-" + this.h;
                }
                httpURLConnection.setRequestProperty("Range", str);
                if (a()) {
                    if (httpURLConnection != null) {
                        try {
                            httpURLConnection.disconnect();
                            return;
                        } catch (Throwable th4) {
                            String unused3 = l.a;
                            new StringBuilder("close failed: ").append(th4.getMessage());
                            return;
                        }
                    }
                    return;
                }
                long j = 0;
                if (this.f1669f <= 0) {
                    this.f1669f = 60000L;
                }
                httpURLConnection.setConnectTimeout((int) this.f1669f);
                httpURLConnection.connect();
                int responseCode = httpURLConnection.getResponseCode();
                if (responseCode != 200 && responseCode != 206) {
                    this.j.a(this.b, c.HTTP_STATUS, "statusCode=" + responseCode + " " + httpURLConnection.getResponseMessage());
                    if (httpURLConnection != null) {
                        try {
                            httpURLConnection.disconnect();
                            return;
                        } catch (Throwable th5) {
                            String unused4 = l.a;
                            new StringBuilder("close failed: ").append(th5.getMessage());
                            return;
                        }
                    }
                    return;
                }
                if (a()) {
                    if (httpURLConnection != null) {
                        try {
                            httpURLConnection.disconnect();
                            return;
                        } catch (Throwable th6) {
                            String unused5 = l.a;
                            new StringBuilder("close failed: ").append(th6.getMessage());
                            return;
                        }
                    }
                    return;
                }
                BufferedInputStream bufferedInputStream = new BufferedInputStream(httpURLConnection.getInputStream());
                RandomAccessFile randomAccessFile = new RandomAccessFile(this.d, "rws");
                randomAccessFile.seek(this.i);
                byte[] bArr = new byte[1048576];
                while (true) {
                    int read = bufferedInputStream.read(bArr, 0, 1048576);
                    if (read == -1) {
                        randomAccessFile.close();
                        bufferedInputStream.close();
                        this.j.c(this.b);
                        if (httpURLConnection != null) {
                            try {
                                httpURLConnection.disconnect();
                                return;
                            } catch (Throwable th7) {
                                String unused6 = l.a;
                                new StringBuilder("close failed: ").append(th7.getMessage());
                                return;
                            }
                        }
                        return;
                    }
                    if (a()) {
                        if (httpURLConnection != null) {
                            try {
                                httpURLConnection.disconnect();
                                return;
                            } catch (Throwable th8) {
                                String unused7 = l.a;
                                new StringBuilder("close failed: ").append(th8.getMessage());
                                return;
                            }
                        }
                        return;
                    }
                    randomAccessFile.write(bArr, 0, read);
                    j += read;
                    this.j.a(this.b, this.i, j);
                }
            } catch (OutOfMemoryError e9) {
                e = e9;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.EXCEPTION, "OutOfMemoryError: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th9) {
                        String unused8 = l.a;
                        new StringBuilder("close failed: ").append(th9.getMessage());
                    }
                }
            } catch (StackOverflowError e10) {
                e = e10;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.EXCEPTION, "StackOverflowError: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th10) {
                        String unused9 = l.a;
                        new StringBuilder("close failed: ").append(th10.getMessage());
                    }
                }
            } catch (Error e11) {
                e = e11;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.EXCEPTION, "Error: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th11) {
                        String unused10 = l.a;
                        new StringBuilder("close failed: ").append(th11.getMessage());
                    }
                }
            } catch (ConnectException e12) {
                e = e12;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.CONNECT_EXCEPTION, "ConnectException: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th12) {
                        String unused11 = l.a;
                        new StringBuilder("close failed: ").append(th12.getMessage());
                    }
                }
            } catch (SocketTimeoutException e13) {
                e = e13;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.HTTP_TIMEOUT, "SocketTimeoutException: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th13) {
                        String unused12 = l.a;
                        new StringBuilder("close failed: ").append(th13.getMessage());
                    }
                }
            } catch (ConnectTimeoutException e14) {
                e = e14;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.HTTP_TIMEOUT, "ConnectTimeoutException: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th14) {
                        String unused13 = l.a;
                        new StringBuilder("close failed: ").append(th14.getMessage());
                    }
                }
            } catch (Exception e15) {
                e = e15;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.EXCEPTION, "Exception: " + e.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th15) {
                        String unused14 = l.a;
                        new StringBuilder("close failed: ").append(th15.getMessage());
                    }
                }
            } catch (Throwable th16) {
                th = th16;
                httpURLConnection2 = httpURLConnection;
                this.j.a(this.b, c.EXCEPTION, "Throwable: " + th.getMessage());
                if (httpURLConnection2 != null) {
                    try {
                        httpURLConnection2.disconnect();
                    } catch (Throwable th17) {
                        String unused15 = l.a;
                        new StringBuilder("close failed: ").append(th17.getMessage());
                    }
                }
            }
        }

        public d(int i, String str, String str2, String str3, long j, int i2, int i3, int i4, e eVar, l lVar) {
            this.b = i;
            this.c = str;
            this.d = str2;
            this.f1668e = str3;
            this.f1669f = j;
            this.g = i2;
            this.h = i3;
            this.i = i4;
            this.j = eVar;
            this.k = lVar;
        }
    }

    public interface e {
        void a(int i);

        void a(int i, int i2);

        void a(int i, int i2, long j);

        void a(int i, c cVar, String str);

        void b(int i);

        void c(int i);
    }

    public class f implements e {
        public static final int l = 100;
        public final AtomicInteger b = new AtomicInteger(0);
        public final AtomicInteger c = new AtomicInteger(0);
        public final AtomicInteger d = new AtomicInteger(0);

        public final AtomicInteger f1670e = new AtomicInteger(0);

        public final AtomicInteger f1671f = new AtomicInteger(0);
        public final AtomicInteger g = new AtomicInteger(0);
        public final AtomicInteger h = new AtomicInteger(0);
        public final SparseIntArray i = new SparseIntArray();
        public HandlerThread j;
        public Handler k;

        public f() {
            try {
                HandlerThread handlerThread = new HandlerThread(l.f());
                this.j = handlerThread;
                handlerThread.start();
                this.k = new Handler(this.j.getLooper()) {
                    @Override
                    public final void handleMessage(Message message) {
                        if (message.what == 100) {
                            long j = 0;
                            for (int i = 0; i < f.this.i.size(); i++) {
                                try {
                                    j += f.this.i.get(i);
                                } catch (Throwable th) {
                                    String unused = l.a;
                                    th.getMessage();
                                    return;
                                }
                            }
                            if (l.this.k != null) {
                                k kVar = l.this.k;
                                SparseIntArray unused2 = f.this.i;
                                kVar.a(j, l.this.g);
                            }
                            if (f.this.k == null || j > l.this.g) {
                                return;
                            }
                            f.this.k.sendMessageDelayed(f.this.k.obtainMessage(100), 500L);
                        }
                    }
                };
            } catch (Throwable th) {
                String unused = l.a;
                th.getMessage();
            }
        }

        @Override
        public final void c(int i) {
            String unused = l.a;
            if (this.f1671f.incrementAndGet() == l.this.f1666f) {
                String a = a(l.this.f1666f, l.this.d);
                if (l.this.k != null) {
                    if (TextUtils.isEmpty(a)) {
                        l.this.j = g.FINISH;
                        l.this.k.a(l.this.j);
                        int i2 = l.this.f1666f;
                        String str = l.this.d;
                        for (int i3 = 0; i3 < i2; i3++) {
                            File file = new File(com.anythink.dlopt.common.c.b.a(str, i3));
                            if (file.exists()) {
                                file.delete();
                            }
                        }
                        k kVar = l.this.k;
                        String unused2 = l.this.b;
                        String unused3 = l.this.d;
                        kVar.a();
                    } else {
                        l.this.j = g.ERROR;
                        l.this.k.a(l.this.j);
                        k kVar2 = l.this.k;
                        String unused4 = l.this.b;
                        kVar2.a(c.EXCEPTION, a);
                    }
                }
                a();
            }
        }

        @Override
        public final void a(int i) {
            String unused = l.a;
            if (this.b.incrementAndGet() == 1) {
                if (l.this.k != null) {
                    l.this.k.a(g.PAUSE);
                }
                a();
            }
        }

        @Override
        public final void b(int i) {
            String unused = l.a;
            if (this.c.incrementAndGet() == 1) {
                if (l.this.k != null) {
                    l.this.k.a(g.STOP);
                }
                a();
            }
        }

        public static void b(int i, String str) {
            for (int i2 = 0; i2 < i; i2++) {
                File file = new File(com.anythink.dlopt.common.c.b.a(str, i2));
                if (file.exists()) {
                    file.delete();
                }
            }
        }

        @Override
        public final void a(int i, int i2) {
            String unused = l.a;
            int addAndGet = this.h.addAndGet(i2);
            if (this.d.incrementAndGet() != l.this.f1666f || l.this.k == null) {
                return;
            }
            l.this.j = g.LOADING;
            l.this.k.a(g.LOADING);
            l.this.k.a(addAndGet, l.this.g, l.this.f1666f);
        }

        @Override
        public final void a(int i, int i2, long j) {
            Handler handler;
            synchronized (this.i) {
                this.i.put(i, (int) (i2 + j));
            }
            if (this.f1670e.get() == 1 || this.f1670e.incrementAndGet() != 1 || (handler = this.k) == null) {
                return;
            }
            this.k.sendMessageDelayed(handler.obtainMessage(100), 500L);
        }

        @Override
        public final void a(int i, c cVar, String str) {
            String unused = l.a;
            if (this.g.incrementAndGet() == 1) {
                l.this.j = g.ERROR;
                l.this.a(cVar, str);
                a();
            }
        }

        private void a() {
            try {
                if (this.k != null) {
                    this.k.removeCallbacksAndMessages(null);
                }
                if (this.j == null || Build.VERSION.SDK_INT < 18) {
                    return;
                }
                this.j.quitSafely();
            } catch (Throwable th) {
                String unused = l.a;
                th.getMessage();
            }
        }

        public static String a(int i, String str) {
            try {
                File file = new File(str);
                if (!file.exists()) {
                    file.createNewFile();
                } else {
                    file.delete();
                    file.createNewFile();
                }
                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
                for (int i2 = 0; i2 < i; i2++) {
                    BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(com.anythink.dlopt.common.c.b.a(str, i2)));
                    byte[] bArr = new byte[1048576];
                    while (true) {
                        int read = bufferedInputStream.read(bArr);
                        if (read != -1) {
                            bufferedOutputStream.write(bArr, 0, read);
                        }
                    }
                    bufferedInputStream.close();
                }
                bufferedOutputStream.close();
                return "";
            } catch (Throwable th) {
                String unused = l.a;
                new StringBuilder("mergeFiles() >>> failed: ").append(th.getMessage());
                return "mergeFiles() >>> failed: " + th.getMessage();
            }
        }
    }

    public enum g {
        IDLE,
        START,
        LOADING,
        PAUSE,
        STOP,
        FINISH,
        ERROR;

        public static g[] a() {
            return new g[]{IDLE, START, LOADING, PAUSE, STOP, FINISH, ERROR};
        }
    }

    public l(byte b2) {
        this();
    }

    public static String f() {
        return "anythink_download_apk";
    }

    public static long h(l lVar) {
        lVar.h = 60000L;
        return 60000L;
    }

    public static int i(l lVar) {
        lVar.i = o.w;
        return o.w;
    }

    private void j() {
        String str = this.b;
        this.f1666f = 1;
        this.l.execute(new d(0, str, com.anythink.dlopt.common.c.b.a(this.d, 0), this.c, this.h, 0, 0, 0, this.m, this, (byte) 0));
    }

    private void k() {
        int i = this.i;
        if (i > 0 && this.g < i) {
            this.f1666f = 1;
        }
        int i2 = this.f1666f;
        SparseIntArray sparseIntArray = new SparseIntArray();
        SparseIntArray sparseIntArray2 = new SparseIntArray();
        SparseIntArray sparseIntArray3 = new SparseIntArray();
        ArrayList arrayList = new ArrayList();
        for (int i3 = 0; i3 < i2; i3++) {
            File file = new File(this.d + "_" + i3);
            if (file.exists()) {
                arrayList.add(file);
            }
        }
        a(sparseIntArray, sparseIntArray2, sparseIntArray3, i2, this.g, this.d);
        if (arrayList.size() > 0 && i2 != arrayList.size()) {
            for (int i4 = 0; i4 < arrayList.size(); i4++) {
                File file2 = (File) arrayList.get(i4);
                if (file2.exists()) {
                    file2.delete();
                }
            }
            a(sparseIntArray, sparseIntArray2, sparseIntArray3, i2, this.g, this.d);
        }
        int i5 = 0;
        while (i5 < i2) {
            this.l.execute(new d(i5, this.b, com.anythink.dlopt.common.c.b.a(this.d, i5), this.c, this.h, sparseIntArray.get(i5), sparseIntArray2.get(i5), sparseIntArray3.get(i5), this.m, this, (byte) 0));
            i5++;
            sparseIntArray3 = sparseIntArray3;
            sparseIntArray2 = sparseIntArray2;
        }
    }

    public static String l() {
        return "anythink_download_apk";
    }

    public l() {
        this.f1666f = 2;
        this.j = g.IDLE;
    }

    private boolean h() {
        return (TextUtils.isEmpty(this.b) || TextUtils.isEmpty(this.d) || this.l == null) ? false : true;
    }

    private void i() {
        if (this.g > 0) {
            if (this.f1665e) {
                k();
                return;
            } else {
                j();
                return;
            }
        }
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(this.b).openConnection();
        httpURLConnection.setRequestMethod("HEAD");
        long contentLength = httpURLConnection.getContentLength();
        this.g = contentLength;
        if (contentLength <= 0) {
            a("downloadSize <= 0");
            return;
        }
        String headerField = httpURLConnection.getHeaderField("Accept-Ranges");
        if (headerField == null || !headerField.equals("bytes")) {
            this.f1665e = false;
            j();
        } else {
            this.f1665e = true;
            k();
        }
    }

    public final void b() {
        this.j = g.PAUSE;
    }

    public final boolean e() {
        return this.f1665e;
    }

    public static String b(String str, int i) {
        return com.anythink.dlopt.common.c.b.a(str, i);
    }

    public final void c() {
        this.j = g.STOP;
    }

    public final g d() {
        return this.j;
    }

    public static void b(l lVar) {
        if (lVar.g > 0) {
            if (lVar.f1665e) {
                lVar.k();
                return;
            } else {
                lVar.j();
                return;
            }
        }
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(lVar.b).openConnection();
        httpURLConnection.setRequestMethod("HEAD");
        long contentLength = httpURLConnection.getContentLength();
        lVar.g = contentLength;
        if (contentLength <= 0) {
            lVar.a("downloadSize <= 0");
            return;
        }
        String headerField = httpURLConnection.getHeaderField("Accept-Ranges");
        if (headerField != null && headerField.equals("bytes")) {
            lVar.f1665e = true;
            lVar.k();
        } else {
            lVar.f1665e = false;
            lVar.j();
        }
    }

    private void a(SparseIntArray sparseIntArray, SparseIntArray sparseIntArray2, SparseIntArray sparseIntArray3, int i, long j, String str) {
        long j2;
        long j3;
        long ceil = (long) Math.ceil(j / i);
        for (int i2 = 0; i2 < i; i2++) {
            File file = new File(com.anythink.dlopt.common.c.b.a(str, i2));
            file.length();
            if (file.exists()) {
                j2 = (i2 * ceil) + file.length();
                j3 = file.length();
            } else if (!file.createNewFile()) {
                a("create part File failed.");
                return;
            } else {
                j2 = i2 * ceil;
                j3 = 0;
            }
            long min = Math.min(((i2 * ceil) + ceil) - 1, j - 1);
            long min2 = Math.min(j2, min);
            long min3 = Math.min(j3, ceil - 1);
            sparseIntArray.put(i2, (int) min2);
            sparseIntArray2.put(i2, (int) min);
            sparseIntArray3.put(i2, (int) min3);
        }
    }

    public void a(String str) {
        a(c.EXCEPTION, str);
    }

    public void a(c cVar, String str) {
        k kVar = this.k;
        if (kVar != null) {
            kVar.a(g.ERROR);
            this.k.a(cVar, str);
        }
    }

    public final void a() {
        if (!((TextUtils.isEmpty(this.b) || TextUtils.isEmpty(this.d) || this.l == null) ? false : true)) {
            a("url, filePath or executorService can not be empty. url: " + this.b + " filePath: " + this.d + " executorService: " + this.l);
            return;
        }
        g gVar = this.j;
        if (gVar == g.START || gVar == g.LOADING) {
            return;
        }
        g gVar2 = g.START;
        this.j = gVar2;
        k kVar = this.k;
        if (kVar != null) {
            kVar.a(gVar2);
        }
        this.m = new f();
        this.l.execute(new b() {
            @Override
            public final void run() {
                super.run();
                try {
                    if (l.this.j == g.LOADING) {
                        return;
                    }
                    l.b(l.this);
                } catch (Throwable th) {
                    String str = null;
                    try {
                        StringWriter stringWriter = new StringWriter();
                        th.printStackTrace(new PrintWriter(stringWriter));
                        str = stringWriter.toString();
                    } catch (Throwable unused) {
                    }
                    l.this.a("DownloadLoader#start() >>> download failed: msg = " + th.getMessage() + ", stackTrace = " + str);
                }
            }
        });
    }
}