1 package com.bumptech.glide.load.model.stream; 2 3 import android.content.Context; 4 import android.net.Uri; 5 6 import com.bumptech.glide.Glide; 7 import com.bumptech.glide.load.data.DataFetcher; 8 import com.bumptech.glide.load.data.StreamAssetPathFetcher; 9 import com.bumptech.glide.load.data.StreamLocalUriFetcher; 10 import com.bumptech.glide.load.model.GenericLoaderFactory; 11 import com.bumptech.glide.load.model.GlideUrl; 12 import com.bumptech.glide.load.model.ModelLoader; 13 import com.bumptech.glide.load.model.ModelLoaderFactory; 14 import com.bumptech.glide.load.model.UriLoader; 15 16 import java.io.InputStream; 17 18 /** 19 * A {@link ModelLoader} for translating uri models into {@link InputStream} data. Capable of handling 'http', 20 * 'https', 'android.resource', 'content', and 'file' schemes. Unsupported schemes will throw an exception in 21 * {@link #getResourceFetcher(Uri, int, int)}. 22 */ 23 public class StreamUriLoader extends UriLoader<InputStream> implements StreamModelLoader<Uri> { 24 25 /** 26 * THe default factory for {@link com.bumptech.glide.load.model.stream.StreamUriLoader}s. 27 */ 28 public static class Factory implements ModelLoaderFactory<Uri, InputStream> { 29 30 @Override 31 public ModelLoader<Uri, InputStream> build(Context context, GenericLoaderFactory factories) { 32 return new StreamUriLoader(context, factories.buildModelLoader(GlideUrl.class, InputStream.class)); 33 } 34 35 @Override 36 public void teardown() { 37 // Do nothing. 38 } 39 } 40 41 public StreamUriLoader(Context context) { 42 this(context, Glide.buildStreamModelLoader(GlideUrl.class, context)); 43 } 44 45 public StreamUriLoader(Context context, ModelLoader<GlideUrl, InputStream> urlLoader) { 46 super(context, urlLoader); 47 } 48 49 @Override 50 protected DataFetcher<InputStream> getLocalUriFetcher(Context context, Uri uri) { 51 return new StreamLocalUriFetcher(context, uri); 52 } 53 54 @Override 55 protected DataFetcher<InputStream> getAssetPathFetcher(Context context, String assetPath) { 56 return new StreamAssetPathFetcher(context.getApplicationContext().getAssets(), assetPath); 57 } 58 } 59