1 package com.bumptech.glide.load.model.stream; 2 3 import android.content.Context; 4 5 import com.bumptech.glide.load.data.ByteArrayFetcher; 6 import com.bumptech.glide.load.data.DataFetcher; 7 import com.bumptech.glide.load.model.GenericLoaderFactory; 8 import com.bumptech.glide.load.model.ModelLoader; 9 import com.bumptech.glide.load.model.ModelLoaderFactory; 10 11 import java.io.InputStream; 12 13 /** 14 * A base class to convert byte arrays to input streams so they can be decoded. This class is abstract because there is 15 * no simple/quick way to generate an id from the bytes themselves, so subclass must include an id. 16 */ 17 public class StreamByteArrayLoader implements StreamModelLoader<byte[]> { 18 private final String id; 19 20 public StreamByteArrayLoader() { 21 this(""); 22 } 23 24 /** 25 * @deprecated Use {@link com.bumptech.glide.GenericRequestBuilder#signature(com.bumptech.glide.load.Key)} 26 * and the empty constructor instead. Scheduled to be removed in Glide 4.0. 27 */ 28 @Deprecated 29 public StreamByteArrayLoader(String id) { 30 this.id = id; 31 } 32 33 @Override 34 public DataFetcher<InputStream> getResourceFetcher(byte[] model, int width, int height) { 35 return new ByteArrayFetcher(model, id); 36 } 37 38 /** 39 * Factory for {@link com.bumptech.glide.load.model.stream.StreamByteArrayLoader}. 40 */ 41 public static class Factory implements ModelLoaderFactory<byte[], InputStream> { 42 43 @Override 44 public ModelLoader<byte[], InputStream> build(Context context, GenericLoaderFactory factories) { 45 return new StreamByteArrayLoader(); 46 } 47 48 @Override 49 public void teardown() { 50 // Do nothing. 51 } 52 } 53 } 54