package com.bumptech.glide.load.resource.bitmap; import android.graphics.Bitmap; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.ResourceDecoder; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.resource.bitmap.Downsampler; import com.bumptech.glide.util.ExceptionCatchingInputStream; import com.bumptech.glide.util.MarkEnforcingInputStream; import java.io.IOException; import java.io.InputStream; /* loaded from: classes.dex */ public class StreamBitmapDecoder implements ResourceDecoder { private final Downsampler a; private final ArrayPool b; static class UntrustedCallbacks implements Downsampler.DecodeCallbacks { private final RecyclableBufferedInputStream a; private final ExceptionCatchingInputStream b; UntrustedCallbacks(RecyclableBufferedInputStream recyclableBufferedInputStream, ExceptionCatchingInputStream exceptionCatchingInputStream) { this.a = recyclableBufferedInputStream; this.b = exceptionCatchingInputStream; } @Override // com.bumptech.glide.load.resource.bitmap.Downsampler.DecodeCallbacks public void a() { this.a.a(); } @Override // com.bumptech.glide.load.resource.bitmap.Downsampler.DecodeCallbacks public void a(BitmapPool bitmapPool, Bitmap bitmap) throws IOException { IOException a = this.b.a(); if (a != null) { if (bitmap == null) { throw a; } bitmapPool.a(bitmap); throw a; } } } public StreamBitmapDecoder(Downsampler downsampler, ArrayPool arrayPool) { this.a = downsampler; this.b = arrayPool; } @Override // com.bumptech.glide.load.ResourceDecoder public boolean a(InputStream inputStream, Options options) { return this.a.a(inputStream); } @Override // com.bumptech.glide.load.ResourceDecoder public Resource a(InputStream inputStream, int i, int i2, Options options) throws IOException { RecyclableBufferedInputStream recyclableBufferedInputStream; boolean z; if (inputStream instanceof RecyclableBufferedInputStream) { recyclableBufferedInputStream = (RecyclableBufferedInputStream) inputStream; z = false; } else { recyclableBufferedInputStream = new RecyclableBufferedInputStream(inputStream, this.b); z = true; } ExceptionCatchingInputStream b = ExceptionCatchingInputStream.b(recyclableBufferedInputStream); try { return this.a.a(new MarkEnforcingInputStream(b), i, i2, options, new UntrustedCallbacks(recyclableBufferedInputStream, b)); } finally { b.b(); if (z) { recyclableBufferedInputStream.b(); } } } }