1 package com.bumptech.glide.load.resource.bitmap; 2 3 import android.graphics.Bitmap; 4 5 import com.bumptech.glide.load.DecodeFormat; 6 import com.bumptech.glide.load.Encoder; 7 import com.bumptech.glide.load.ResourceDecoder; 8 import com.bumptech.glide.load.ResourceEncoder; 9 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 10 import com.bumptech.glide.load.model.StreamEncoder; 11 import com.bumptech.glide.load.resource.file.FileToStreamDecoder; 12 import com.bumptech.glide.provider.DataLoadProvider; 13 14 import java.io.File; 15 import java.io.InputStream; 16 17 /** 18 * An {@link com.bumptech.glide.provider.DataLoadProvider} that provides decoders and encoders for decoding and caching 19 * {@link android.graphics.Bitmap}s using {@link java.io.InputStream} data. 20 */ 21 public class StreamBitmapDataLoadProvider implements DataLoadProvider<InputStream, Bitmap> { 22 private final StreamBitmapDecoder decoder; 23 private final BitmapEncoder encoder; 24 private final StreamEncoder sourceEncoder; 25 private final FileToStreamDecoder<Bitmap> cacheDecoder; 26 27 public StreamBitmapDataLoadProvider(BitmapPool bitmapPool, DecodeFormat decodeFormat) { 28 sourceEncoder = new StreamEncoder(); 29 decoder = new StreamBitmapDecoder(bitmapPool, decodeFormat); 30 encoder = new BitmapEncoder(); 31 cacheDecoder = new FileToStreamDecoder<Bitmap>(decoder); 32 } 33 34 @Override 35 public ResourceDecoder<File, Bitmap> getCacheDecoder() { 36 return cacheDecoder; 37 } 38 39 @Override 40 public ResourceDecoder<InputStream, Bitmap> getSourceDecoder() { 41 return decoder; 42 } 43 44 @Override 45 public Encoder<InputStream> getSourceEncoder() { 46 return sourceEncoder; 47 } 48 49 @Override 50 public ResourceEncoder<Bitmap> getEncoder() { 51 return encoder; 52 } 53 } 54