package com.cvte.dss.ups.main;

import io.netty.handler.codec.http2.Http2CodecUtil;
import java.io.File;
import java.io.FileInputStream;
import java.util.logging.Logger;
import kotlin.jvm.internal.o;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.n0.c;
import okio.BufferedSink;
import okio.InputStreamSource;
import okio.Timeout;
import okio.n;

/* JADX INFO: loaded from: classes.dex */
public class CountingFileRequestBody extends RequestBody {
    private static final int SEGMENT_SIZE = 8192;
    private final String contentType;
    private final File file;
    private final ProgressListener listener;

    public interface ProgressListener {
        void transferred(float f2);
    }

    public CountingFileRequestBody(File file, String str, ProgressListener progressListener) {
        this.file = file;
        this.contentType = str;
        this.listener = progressListener;
    }

    @Override // okhttp3.RequestBody
    public long contentLength() {
        return this.file.length();
    }

    @Override // okhttp3.RequestBody
    /* JADX INFO: renamed from: contentType */
    public MediaType getF9557j() {
        return MediaType.c(this.contentType);
    }

    @Override // okhttp3.RequestBody
    public void writeTo(BufferedSink bufferedSink) throws Throwable {
        InputStreamSource inputStreamSource;
        try {
            File file = this.file;
            Logger logger = n.a;
            o.f(file, "<this>");
            inputStreamSource = new InputStreamSource(new FileInputStream(file), Timeout.a);
            long j2 = 0;
            while (true) {
                try {
                    long jR = inputStreamSource.r(bufferedSink.buffer(), Http2CodecUtil.DEFAULT_HEADER_LIST_SIZE);
                    if (jR == -1) {
                        c.e(inputStreamSource);
                        return;
                    } else {
                        j2 += jR;
                        bufferedSink.flush();
                        this.listener.transferred(((j2 * 1.0f) / contentLength()) * 100.0f);
                    }
                } catch (Throwable th) {
                    th = th;
                    if (inputStreamSource != null) {
                        c.e(inputStreamSource);
                    }
                    throw th;
                }
            }
        } catch (Throwable th2) {
            th = th2;
            inputStreamSource = null;
        }
    }
}
