1 package com.bumptech.glide.load.model; 2 3 import android.content.ContentResolver; 4 import android.net.Uri; 5 6 /** 7 * A utility class for parsing Asset uris that look like: file:///android_asset/some/path/in/assets/folder. 8 */ 9 final class AssetUriParser { 10 private static final String ASSET_PATH_SEGMENT = "android_asset"; 11 private static final String ASSET_PREFIX = ContentResolver.SCHEME_FILE + ":///" + ASSET_PATH_SEGMENT + "/"; 12 private static final int ASSET_PREFIX_LENGTH = ASSET_PREFIX.length(); 13 14 private AssetUriParser() { 15 // Utility constructor. 16 } 17 18 /** 19 * Returns true if the given {@link android.net.Uri} matches the asset uri pattern. 20 */ 21 public static boolean isAssetUri(Uri uri) { 22 return ContentResolver.SCHEME_FILE.equals(uri.getScheme()) && !uri.getPathSegments().isEmpty() 23 && ASSET_PATH_SEGMENT.equals(uri.getPathSegments().get(0)); 24 } 25 26 /** 27 * Returns the string path for the given asset uri. 28 * 29 * <p> 30 * Assumes the given {@link android.net.Uri} is in fact an asset uri. 31 * </p> 32 */ 33 public static String toAssetPath(Uri uri) { 34 return uri.toString().substring(ASSET_PREFIX_LENGTH); 35 } 36 } 37