package net.gotev.uploadservice.http;

import java.io.IOException;
import java.io.InputStream;
import net.gotev.uploadservice.UploadService;
/* loaded from: classes.dex */
public abstract class BodyWriter {

    /* loaded from: classes.dex */
    public interface OnStreamWriteListener {
        void onBytesWritten(int i);

        boolean shouldContinueWriting();
    }

    public abstract void flush() throws IOException;

    public abstract void write(byte[] bArr) throws IOException;

    public abstract void write(byte[] bArr, int i) throws IOException;

    public final void writeStream(InputStream inputStream, OnStreamWriteListener onStreamWriteListener) throws IOException {
        int read;
        if (onStreamWriteListener == null) {
            throw new IllegalArgumentException("listener MUST not be null!");
        }
        int i = UploadService.BUFFER_SIZE;
        byte[] bArr = new byte[i];
        while (onStreamWriteListener.shouldContinueWriting() && (read = inputStream.read(bArr, 0, i)) > 0) {
            write(bArr, read);
            flush();
            onStreamWriteListener.onBytesWritten(read);
        }
    }
}
