package ඓ.ῲ.K.ᕣ.㳳;

import android.util.Log;
import com.facebook.internal.NativeProtocol;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import ඓ.ῲ.K.ᕣ.AbstractC1031;
import ඓ.ῲ.K.ᕣ.C1121;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0967;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.C0964;

/* renamed from: ඓ.ῲ.K.ᕣ.㳳.䀟  reason: contains not printable characters */
/* compiled from: StreamEncoder */
public class C1116 implements AbstractC1031<InputStream> {

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC0967 f4580;

    public C1116(AbstractC0967 r1) {
        this.f4580 = r1;
    }

    /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.io.File, ඓ.ῲ.K.ᕣ.㸾] */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x003c A[Catch:{ all -> 0x0031 }] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x0043  */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0050 A[SYNTHETIC, Splitter:B:28:0x0050] */
    @Override // ඓ.ῲ.K.ᕣ.AbstractC1031
    /* renamed from: K  reason: contains not printable characters */
    public boolean m2995(InputStream inputStream, File file, C1121 r7) {
        Throwable th;
        IOException e;
        InputStream inputStream2 = inputStream;
        byte[] bArr = (byte[]) ((C0964) this.f4580).m2735(NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST, byte[].class);
        boolean z = false;
        FileOutputStream fileOutputStream = null;
        try {
            FileOutputStream fileOutputStream2 = new FileOutputStream(file);
            while (true) {
                try {
                    int read = inputStream2.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    fileOutputStream2.write(bArr, 0, read);
                } catch (IOException e2) {
                    e = e2;
                    fileOutputStream = fileOutputStream2;
                    try {
                        if (Log.isLoggable("StreamEncoder", 3)) {
                            Log.d("StreamEncoder", "Failed to encode data onto the OutputStream", e);
                        }
                        if (fileOutputStream != null) {
                            fileOutputStream.close();
                        }
                        ((C0964) this.f4580).m2743(bArr);
                        return z;
                    } catch (Throwable th2) {
                        th = th2;
                        fileOutputStream2 = fileOutputStream;
                        if (fileOutputStream2 != null) {
                            try {
                                fileOutputStream2.close();
                            } catch (IOException unused) {
                            }
                        }
                        ((C0964) this.f4580).m2743(bArr);
                        throw th;
                    }
                } catch (Throwable th3) {
                    th = th3;
                    if (fileOutputStream2 != null) {
                    }
                    ((C0964) this.f4580).m2743(bArr);
                    throw th;
                }
            }
            fileOutputStream2.close();
            z = true;
            try {
                fileOutputStream2.close();
            } catch (IOException unused2) {
            }
        } catch (IOException e3) {
            e = e3;
            if (Log.isLoggable("StreamEncoder", 3)) {
            }
            if (fileOutputStream != null) {
            }
            ((C0964) this.f4580).m2743(bArr);
            return z;
        }
        ((C0964) this.f4580).m2743(bArr);
        return z;
    }
}
