红果免费短剧 v6.2.3.32版本的 MD5 值为:a6b05492607eab2c8a25f26d2f238ae0

以下内容为反编译后的 GeckoNetImplTTNet.java 源代码,内容仅作参考


package com.dragon.read.hybrid.gecko;

import android.content.Context;
import android.net.Uri;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import com.bytedance.common.utility.collection.CollectionUtils;
import com.bytedance.frameworks.baselib.network.http.util.UrlUtils;
import com.bytedance.geckox.buffer.stream.BufferOutputStream;
import com.bytedance.geckox.logger.GeckoLogger;
import com.bytedance.geckox.net.INetWork;
import com.bytedance.geckox.net.Response;
import com.bytedance.geckox.utils.CloseableUtils;
import com.bytedance.retrofit2.Call;
import com.bytedance.retrofit2.SsResponse;
import com.bytedance.retrofit2.client.Header;
import com.bytedance.retrofit2.http.Body;
import com.bytedance.retrofit2.http.FieldMap;
import com.bytedance.retrofit2.http.FormUrlEncoded;
import com.bytedance.retrofit2.http.GET;
import com.bytedance.retrofit2.http.HeaderList;
import com.bytedance.retrofit2.http.POST;
import com.bytedance.retrofit2.http.Streaming;
import com.bytedance.retrofit2.http.Url;
import com.bytedance.retrofit2.mime.TypedByteArray;
import com.bytedance.retrofit2.mime.TypedInput;
import com.bytedance.retrofit2.mime.TypedOutput;
import com.bytedance.ttnet.utils.RetrofitUtils;
import com.bytedance.vmsdk.a.a.b.i;
import com.dragon.read.base.util.LogHelper;
import com.dragon.read.util.DebugManager;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class GeckoNetImplTTNet implements INetWork {

    private static final LogHelper f67871c = new LogHelper("GeckoNetworkImpl", 4, true);

    private File f67872a;

    private GeckoxNetApi f67873b = (GeckoxNetApi) RetrofitUtils.createSsService("https://gecko.zijieapi.com", GeckoxNetApi.class);

    public interface GeckoxNetApi {
        @GET
        Call<String> doGet(@Url String str);

        @FormUrlEncoded
        @POST
        Call<String> doPost(@Url String str, @FieldMap Map<String, String> map);

        @GET
        @Streaming
        Call<TypedInput> downloadFile(@Url String str, @HeaderList List<Header> list);

        @POST
        Call<String> postBody(@Url String str, @Body TypedOutput typedOutput);
    }

    public GeckoNetImplTTNet(Context context) {
        File file = new File(context.getFilesDir(), "gecko-resume-net-work");
        this.f67872a = file;
        file.mkdirs();
    }

    @Override
    public Response doGet(String str) throws Exception {
        SsResponse<String> execute = this.f67873b.doGet((String) UrlUtils.parseUrl(str, new LinkedHashMap()).second).execute();
        return new Response(a(execute.headers(), str), execute.body(), execute.code(), execute.raw().getReason());
    }

    private void a(File file, RandomAccessFile randomAccessFile) {
        if (randomAccessFile != null) {
            try {
                randomAccessFile.seek(0L);
                randomAccessFile.writeLong(0L);
            } catch (Exception e) {
                GeckoLogger.w("gecko-debug-tag", "resume-network-reset:", e);
            }
        }
        if (file != null && !file.delete()) {
            GeckoLogger.d("gecko-debug-tag", "删除断点文件失败 ", file.getAbsolutePath());
        }
        CloseableUtils.close(randomAccessFile);
    }

    @Override
    public Response doPost(String str, String str2) throws Exception {
        SsResponse<String> execute = this.f67873b.postBody((String) UrlUtils.parseUrl(str, new LinkedHashMap()).second, new TypedByteArray("application/json", str2.getBytes(Charset.forName(i.f34394a)), new String[0])).execute();
        return new Response(a(execute.headers(), str), execute.body(), execute.code(), execute.raw().getReason());
    }

    private Map<String, String> a(List<Header> list, String str) {
        HashMap hashMap = new HashMap();
        if (!CollectionUtils.isEmpty(list)) {
            for (Header header : list) {
                hashMap.put(header.getName(), header.getValue());
            }
        }
        long elapsedRealtime = SystemClock.elapsedRealtime();
        String geckoLane = DebugManager.inst().getGeckoLane();
        try {
            try {
                if (!TextUtils.isEmpty(geckoLane)) {
                    LogHelper logHelper = f67871c;
                    logHelper.i("当前泳道环境为: %s", geckoLane);
                    List<Header> a2 = a.f67876a.a(str, null);
                    logHelper.i("添加%s泳道", geckoLane);
                    for (Header header2 : a2) {
                        hashMap.put(header2.getName(), header2.getValue());
                    }
                }
                f67871c.w("try to add interceptor, lane=%s, cost time=%s", geckoLane, Long.valueOf(SystemClock.elapsedRealtime() - elapsedRealtime));
            } catch (Exception e) {
                LogHelper logHelper2 = f67871c;
                logHelper2.e("fail to add interceptor, error = %s", e);
                logHelper2.w("try to add interceptor, lane=%s, cost time=%s", geckoLane, Long.valueOf(SystemClock.elapsedRealtime() - elapsedRealtime));
            }
            return hashMap;
        } catch (Throwable th) {
            f67871c.w("try to add interceptor, lane=%s, cost time=%s", geckoLane, Long.valueOf(SystemClock.elapsedRealtime() - elapsedRealtime));
            throw th;
        }
    }

    @Override
    public Response doPost(String str, List<Pair<String, String>> list) throws Exception {
        HashMap hashMap = new HashMap();
        if (!CollectionUtils.isEmpty(list)) {
            for (Pair<String, String> pair : list) {
                hashMap.put((String) pair.first, (String) pair.second);
            }
        }
        SsResponse<String> execute = this.f67873b.doPost(str, hashMap).execute();
        return new Response(a(execute.headers(), str), execute.body(), execute.code(), execute.raw().getReason());
    }

    @Override
    public void downloadFile(String str, long j, BufferOutputStream bufferOutputStream) throws Exception {
        int code;
        BufferedInputStream bufferedInputStream;
        BufferedInputStream bufferedInputStream2 = null;
        int i = 0;
        try {
            try {
                SsResponse<TypedInput> execute = this.f67873b.downloadFile(str, null).execute();
                code = execute.code();
                try {
                    bufferedInputStream = new BufferedInputStream(execute.body().in());
                } catch (Exception e) {
                    e = e;
                    i = code;
                }
            } catch (Exception e2) {
                e = e2;
            }
        } catch (Throwable th) {
            th = th;
        }
        try {
            byte[] bArr = new byte[2048];
            while (true) {
                int read = bufferedInputStream.read(bArr, 0, 2048);
                if (read != -1) {
                    bufferOutputStream.write(bArr, 0, read);
                } else {
                    CloseableUtils.close(bufferedInputStream);
                    return;
                }
            }
        } catch (Exception e3) {
            e = e3;
            i = code;
            bufferedInputStream2 = bufferedInputStream;
            throw new RuntimeException("downloadFile failed, code: " + i + ", caused by:" + e.getMessage(), e);
        } catch (Throwable th2) {
            th = th2;
            bufferedInputStream2 = bufferedInputStream;
            CloseableUtils.close(bufferedInputStream2);
            throw th;
        }
    }

    public void a(String str, long j, BufferOutputStream bufferOutputStream) throws Exception {
        File file;
        RandomAccessFile randomAccessFile;
        long j2;
        int i;
        BufferedInputStream bufferedInputStream;
        int code;
        BufferedInputStream bufferedInputStream2;
        byte[] bArr;
        int read;
        try {
            file = new File(this.f67872a, Uri.parse(str).getPath().replace("/", "-"));
        } catch (Exception e) {
            e = e;
            file = null;
        }
        try {
            try {
                try {
                    randomAccessFile = new RandomAccessFile(file, "rw");
                } catch (Exception e2) {
                    e = e2;
                    randomAccessFile = null;
                    GeckoLogger.w("gecko-debug-tag", "读取断点续传位置失败:" + str, e);
                    j2 = 0;
                    i = 0;
                    ArrayList arrayList = new ArrayList();
                    arrayList.add(new Header("RANGE", "bytes=" + j2 + "-"));
                    SsResponse<TypedInput> execute = this.f67873b.downloadFile(str, arrayList).execute();
                    code = execute.code();
                    bufferedInputStream2 = new BufferedInputStream(execute.body().in());
                    try {
                        try {
                            bArr = new byte[2048];
                            while (true) {
                                read = bufferedInputStream2.read(bArr, 0, 2048);
                                if (read == -1) {
                                }
                                bArr = r19;
                            }
                        } catch (Exception e3) {
                            e = e3;
                            i = code;
                            bufferedInputStream = bufferedInputStream2;
                            try {
                                throw new RuntimeException("downloadFile failed, code: " + i + ", caused by:" + e.getMessage(), e);
                            } catch (Throwable th) {
                                th = th;
                                CloseableUtils.close(bufferedInputStream);
                                throw th;
                            }
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        bufferedInputStream = bufferedInputStream2;
                        CloseableUtils.close(bufferedInputStream);
                        throw th;
                    }
                }
                try {
                } catch (Exception e4) {
                    e = e4;
                    GeckoLogger.w("gecko-debug-tag", "读取断点续传位置失败:" + str, e);
                    j2 = 0;
                    i = 0;
                    ArrayList arrayList2 = new ArrayList();
                    arrayList2.add(new Header("RANGE", "bytes=" + j2 + "-"));
                    SsResponse<TypedInput> execute2 = this.f67873b.downloadFile(str, arrayList2).execute();
                    code = execute2.code();
                    bufferedInputStream2 = new BufferedInputStream(execute2.body().in());
                    bArr = new byte[2048];
                    while (true) {
                        read = bufferedInputStream2.read(bArr, 0, 2048);
                        if (read == -1) {
                        }
                        bArr = r19;
                    }
                }
            } catch (Exception e5) {
                e = e5;
            }
            try {
                if (randomAccessFile.length() != 0) {
                    j2 = randomAccessFile.readLong();
                    i = 0;
                    ArrayList arrayList22 = new ArrayList();
                    arrayList22.add(new Header("RANGE", "bytes=" + j2 + "-"));
                    SsResponse<TypedInput> execute22 = this.f67873b.downloadFile(str, arrayList22).execute();
                    code = execute22.code();
                    bufferedInputStream2 = new BufferedInputStream(execute22.body().in());
                    bArr = new byte[2048];
                    while (true) {
                        read = bufferedInputStream2.read(bArr, 0, 2048);
                        if (read == -1) {
                            byte[] bArr2 = bArr;
                            bufferOutputStream.write(j2, bArr2, 0, read);
                            bufferOutputStream.flush();
                            j2 += read;
                            if (randomAccessFile != null) {
                                try {
                                    randomAccessFile.seek(0L);
                                    randomAccessFile.writeLong(j2);
                                } catch (Exception e6) {
                                    GeckoLogger.w("gecko-debug-tag", "写入断点失败", e6);
                                }
                            }
                            bArr = bArr2;
                        } else {
                            a(file, randomAccessFile);
                            CloseableUtils.close(bufferedInputStream2);
                            return;
                        }
                    }
                }
                bufferedInputStream2 = new BufferedInputStream(execute22.body().in());
                bArr = new byte[2048];
                while (true) {
                    read = bufferedInputStream2.read(bArr, 0, 2048);
                    if (read == -1) {
                    }
                    bArr = bArr2;
                }
            } catch (Exception e7) {
                e = e7;
                i = code;
                bufferedInputStream = null;
                throw new RuntimeException("downloadFile failed, code: " + i + ", caused by:" + e.getMessage(), e);
            }
            ArrayList arrayList222 = new ArrayList();
            arrayList222.add(new Header("RANGE", "bytes=" + j2 + "-"));
            SsResponse<TypedInput> execute222 = this.f67873b.downloadFile(str, arrayList222).execute();
            code = execute222.code();
        } catch (Throwable th3) {
            th = th3;
            bufferedInputStream = null;
        }
        j2 = 0;
        i = 0;
    }
}