package com.bumptech.glide.load.resource.gif; import android.util.Log; import com.bumptech.glide.load.ImageHeaderParser; import com.bumptech.glide.load.ImageHeaderParserUtils; 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 java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.List; /* loaded from: classes.dex */ public class StreamGifDecoder implements ResourceDecoder { private final List a; private final ResourceDecoder b; private final ArrayPool c; public StreamGifDecoder(List list, ResourceDecoder resourceDecoder, ArrayPool arrayPool) { this.a = list; this.b = resourceDecoder; this.c = arrayPool; } @Override // com.bumptech.glide.load.ResourceDecoder public boolean a(InputStream inputStream, Options options) throws IOException { return !((Boolean) options.a(GifOptions.b)).booleanValue() && ImageHeaderParserUtils.b(this.a, inputStream, this.c) == ImageHeaderParser.ImageType.GIF; } @Override // com.bumptech.glide.load.ResourceDecoder public Resource a(InputStream inputStream, int i, int i2, Options options) throws IOException { byte[] a = a(inputStream); if (a == null) { return null; } return this.b.a(ByteBuffer.wrap(a), i, i2, options); } private static byte[] a(InputStream inputStream) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(16384); try { byte[] bArr = new byte[16384]; while (true) { int read = inputStream.read(bArr); if (read != -1) { byteArrayOutputStream.write(bArr, 0, read); } else { byteArrayOutputStream.flush(); return byteArrayOutputStream.toByteArray(); } } } catch (IOException e) { if (!Log.isLoggable("StreamGifDecoder", 5)) { return null; } Log.w("StreamGifDecoder", "Error reading data from stream", e); return null; } } }