package p138.p145.p146.p151.p158;

import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import p138.p145.p146.p151.C2848;
import p138.p145.p146.p151.InterfaceC2843;
import p138.p145.p146.p151.p154.p155.InterfaceC2940;

/* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ދ.ޑ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C3045 implements InterfaceC2843<InputStream> {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final InterfaceC2940 f9230;

    public C3045(InterfaceC2940 interfaceC2940) {
        this.f9230 = interfaceC2940;
    }

    @Override // p138.p145.p146.p151.InterfaceC2843
    /* JADX INFO: renamed from: ֏ */
    public boolean mo4976(InputStream inputStream, File file, C2848 c2848) throws Throwable {
        FileOutputStream fileOutputStream;
        InputStream inputStream2 = inputStream;
        byte[] bArr = (byte[]) this.f9230.mo5081(65536, byte[].class);
        boolean z = false;
        FileOutputStream fileOutputStream2 = null;
        try {
            try {
                try {
                    fileOutputStream = new FileOutputStream(file);
                } catch (IOException unused) {
                }
            } catch (IOException e) {
                e = e;
            }
            while (true) {
                try {
                    int i = inputStream2.read(bArr);
                    if (i == -1) {
                        break;
                    }
                    fileOutputStream.write(bArr, 0, i);
                } catch (IOException e2) {
                    e = e2;
                    fileOutputStream2 = fileOutputStream;
                    if (Log.isLoggable("StreamEncoder", 3)) {
                        Log.d("StreamEncoder", "Failed to encode data onto the OutputStream", e);
                    }
                    if (fileOutputStream2 != null) {
                        fileOutputStream2.close();
                    }
                    this.f9230.mo5080(bArr);
                    return z;
                } catch (Throwable th) {
                    th = th;
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException unused2) {
                        }
                    }
                    this.f9230.mo5080(bArr);
                    throw th;
                }
                this.f9230.mo5080(bArr);
                return z;
            }
            fileOutputStream.close();
            z = true;
            fileOutputStream.close();
            this.f9230.mo5080(bArr);
            return z;
        } catch (Throwable th2) {
            th = th2;
            fileOutputStream = fileOutputStream2;
        }
    }
}
