package com.discord.utilities.file; import android.content.Context; import com.discord.utilities.file.DownloadUtils; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import d0.z.d.m; import d0.z.d.o; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import okhttp3.ResponseBody; import rx.Emitter; import rx.functions.Action1; /* compiled from: DownloadUtils.kt */ public final class DownloadUtils$downloadFile$1 implements Action1> { public final /* synthetic */ File $downloadDirectory; public final /* synthetic */ String $fileName; public final /* synthetic */ String $fileUrl; /* compiled from: DownloadUtils.kt */ /* renamed from: com.discord.utilities.file.DownloadUtils$downloadFile$1$1 reason: invalid class name */ public static final class AnonymousClass1 extends o implements Function1 { public final /* synthetic */ Emitter $emitter; public final /* synthetic */ DownloadUtils$downloadFile$1 this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(DownloadUtils$downloadFile$1 downloadUtils$downloadFile$1, Emitter emitter) { super(1); this.this$0 = downloadUtils$downloadFile$1; this.$emitter = emitter; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(ResponseBody responseBody) { invoke(responseBody); return Unit.a; } /* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: rx.Emitter */ /* JADX DEBUG: Multi-variable search result rejected for r1v5, resolved type: rx.Emitter */ /* JADX DEBUG: Multi-variable search result rejected for r7v1, resolved type: rx.Emitter */ /* JADX WARN: Multi-variable type inference failed */ public final void invoke(ResponseBody responseBody) { m.checkNotNullParameter(responseBody, "responseBody"); try { DownloadUtils$downloadFile$1 downloadUtils$downloadFile$1 = this.this$0; File file = new File(downloadUtils$downloadFile$1.$downloadDirectory, downloadUtils$downloadFile$1.$fileName); byte[] bArr = new byte[8192]; FileOutputStream fileOutputStream = new FileOutputStream(file); float a = (float) responseBody.a(); int i = 0; while (true) { int read = responseBody.c().t0().read(bArr); if (read == -1) { break; } i += read; this.$emitter.onNext(new DownloadUtils.DownloadState.InProgress(((float) i) / a)); fileOutputStream.write(bArr, 0, read); } this.$emitter.onNext(new DownloadUtils.DownloadState.Completed(file)); this.$emitter.onCompleted(); } catch (IOException e) { e.printStackTrace(); this.$emitter.onNext(new DownloadUtils.DownloadState.Failure(e)); } catch (Throwable th) { responseBody.close(); throw th; } responseBody.close(); } } public DownloadUtils$downloadFile$1(String str, File file, String str2) { this.$fileUrl = str; this.$downloadDirectory = file; this.$fileName = str2; } public final void call(Emitter emitter) { m.checkNotNullParameter(emitter, "emitter"); emitter.onNext(new DownloadUtils.DownloadState.InProgress(0.0f)); ObservableExtensionsKt.appSubscribe$default(RestAPI.Companion.getApiFiles().getFile(this.$fileUrl), DownloadUtils.INSTANCE.getClass(), (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this, emitter), 62, (Object) null); } }