package coil.fetch;

import A4.d;
import coil.ImageLoader;
import coil.decode.DataSource;
import coil.decode.ImageSources;
import coil.fetch.Fetcher;
import coil.request.Options;
import java.nio.ByteBuffer;
import p5.C2740j;

/* JADX INFO: loaded from: classes.dex */
public final class ByteBufferFetcher implements Fetcher {
    private final ByteBuffer data;
    private final Options options;

    public static final class Factory implements Fetcher.Factory<ByteBuffer> {
        @Override // coil.fetch.Fetcher.Factory
        public Fetcher create(ByteBuffer byteBuffer, Options options, ImageLoader imageLoader) {
            return new ByteBufferFetcher(byteBuffer, options);
        }
    }

    public ByteBufferFetcher(ByteBuffer byteBuffer, Options options) {
        this.data = byteBuffer;
        this.options = options;
    }

    @Override // coil.fetch.Fetcher
    public Object fetch(d dVar) {
        try {
            C2740j c2740j = new C2740j();
            c2740j.write(this.data);
            this.data.position(0);
            return new SourceResult(ImageSources.create(c2740j, this.options.getContext()), null, DataSource.MEMORY);
        } catch (Throwable th) {
            this.data.position(0);
            throw th;
        }
    }
}
