package com.bumptech.glide.load.model; import android.util.Log; import com.bumptech.glide.load.Encoder; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; /* loaded from: classes.dex */ public class StreamEncoder implements Encoder { private final ArrayPool a; public StreamEncoder(ArrayPool arrayPool) { this.a = arrayPool; } @Override // com.bumptech.glide.load.Encoder public boolean a(InputStream inputStream, File file, Options options) { byte[] bArr = (byte[]) this.a.b(65536, byte[].class); boolean z = false; FileOutputStream fileOutputStream = null; try { try { try { FileOutputStream fileOutputStream2 = new FileOutputStream(file); while (true) { try { int read = inputStream.read(bArr); if (read == -1) { break; } fileOutputStream2.write(bArr, 0, read); } catch (IOException e) { e = e; fileOutputStream = fileOutputStream2; if (Log.isLoggable("StreamEncoder", 3)) { Log.d("StreamEncoder", "Failed to encode data onto the OutputStream", e); } if (fileOutputStream != null) { fileOutputStream.close(); } this.a.put(bArr); return z; } catch (Throwable th) { th = th; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused) { } } this.a.put(bArr); throw th; } } fileOutputStream2.close(); z = true; fileOutputStream2.close(); } catch (Throwable th2) { th = th2; } } catch (IOException e2) { e = e2; } } catch (IOException unused2) { } this.a.put(bArr); return z; } }