package com.cvte.dss.ups.main;

import f.a.y.a;
import j.b0;
import j.f;
import j.p;
import java.io.File;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.internal.Util;

/* 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
    public MediaType contentType() {
        return MediaType.parse(this.contentType);
    }

    @Override // okhttp3.RequestBody
    public void writeTo(f fVar) throws IOException {
        b0 b0VarV0 = null;
        try {
            b0VarV0 = a.V0(this.file);
            long j2 = 0;
            while (true) {
                long j3 = ((p) b0VarV0).read(fVar.buffer(), 8192L);
                if (j3 == -1) {
                    Util.closeQuietly(b0VarV0);
                    return;
                } else {
                    j2 += j3;
                    fVar.flush();
                    this.listener.transferred(((j2 * 1.0f) / contentLength()) * 100.0f);
                }
            }
        } catch (Throwable th) {
            if (b0VarV0 != null) {
                Util.closeQuietly(b0VarV0);
            }
            throw th;
        }
    }
}
