package com.cvte.dss.ups.dth_typc;

import f.a.y.a;
import j.d;
import j.f;
import j.j;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/* JADX INFO: loaded from: classes.dex */
public class UploadProgressBody extends RequestBody {
    private f mBufferedSink;
    private Callback mCallback;
    private RequestBody mRequestBody;

    public interface Callback {
        void onProgress(long j2, long j3);
    }

    public UploadProgressBody(RequestBody requestBody, Callback callback) {
        this.mRequestBody = requestBody;
        this.mCallback = callback;
    }

    @Override // okhttp3.RequestBody
    public long contentLength() throws IOException {
        return this.mRequestBody.contentLength();
    }

    @Override // okhttp3.RequestBody
    public MediaType contentType() {
        return this.mRequestBody.contentType();
    }

    @Override // okhttp3.RequestBody
    public void writeTo(f fVar) throws IOException {
        if (this.mBufferedSink == null) {
            this.mBufferedSink = a.s(new j(fVar) { // from class: com.cvte.dss.ups.dth_typc.UploadProgressBody.1
                public long bytesWritten = 0;
                public long contentLength = 0;

                @Override // j.j, j.z
                public void write(d dVar, long j2) throws IOException {
                    super.write(dVar, j2);
                    if (this.contentLength == 0) {
                        this.contentLength = UploadProgressBody.this.contentLength();
                    }
                    this.bytesWritten += j2;
                    if (UploadProgressBody.this.mCallback != null) {
                        UploadProgressBody.this.mCallback.onProgress(this.contentLength, this.bytesWritten);
                    }
                }
            });
        }
        this.mRequestBody.writeTo(this.mBufferedSink);
        this.mBufferedSink.flush();
    }
}
