26
26
* Implementations have to be thread-safe.
27
27
*
28
28
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
29
- * @author Leo Link (mr[dot]leolink[at]gmail[dot]com)
30
29
* @since 1.4.0
31
30
*/
32
31
public interface ImageDownloader {
@@ -43,29 +42,17 @@ public interface ImageDownloader {
43
42
InputStream getStream (String imageUri , Object extra ) throws IOException ;
44
43
45
44
/** Represents supported schemes(protocols) of URI. Provides convenient methods for work with schemes and URIs. */
46
- enum Scheme {
47
- HTTP ("http" , true ),
48
- HTTPS ("https" , true ),
49
- FILE ("file" , true ),
50
- CONTENT ("content" , true ),
51
- ASSETS ("assets" , true ),
52
- DRAWABLE ("drawable" , true ),
53
- BASE64 ("^data:image/[a-zA-Z]{3,};base64,([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)" , false ),
54
- UNKNOWN ("" , false );
45
+ public enum Scheme {
46
+ HTTP ("http" ), HTTPS ("https" ), FILE ("file" ), CONTENT ("content" ), ASSETS ("assets" ), DRAWABLE ("drawable" ), BASE64 ("base64" ), UNKNOWN ("" );
55
47
56
48
private String scheme ;
57
- private String pattern ;
49
+ private String uriPrefix ;
58
50
59
- Scheme (String scheme , boolean isScheme ) {
60
- this .scheme = scheme ;
61
- if (isScheme ) {
62
- this .pattern = "^" + scheme + "://.+?$" ;
63
- } else {
64
- this .pattern = scheme ;
65
- }
51
+ Scheme (String scheme ) {
52
+ this .scheme = scheme ;
53
+ uriPrefix = scheme + "://" ;
66
54
}
67
55
68
-
69
56
/**
70
57
* Defines scheme of incoming URI
71
58
*
@@ -84,24 +71,20 @@ public static Scheme ofUri(String uri) {
84
71
}
85
72
86
73
private boolean belongsTo (String uri ) {
87
- return uri .toLowerCase (Locale .US ).matches ( pattern );
74
+ return uri .toLowerCase (Locale .US ).startsWith ( uriPrefix );
88
75
}
89
76
90
77
/** Appends scheme to incoming path */
91
78
public String wrap (String path ) {
92
- return getUriPrefix () + path ;
79
+ return uriPrefix + path ;
93
80
}
94
81
95
82
/** Removed scheme part ("scheme://") from incoming URI */
96
83
public String crop (String uri ) {
97
84
if (!belongsTo (uri )) {
98
85
throw new IllegalArgumentException (String .format ("URI [%1$s] doesn't have expected scheme [%2$s]" , uri , scheme ));
99
86
}
100
- return uri .substring (getUriPrefix () .length ());
87
+ return uri .substring (uriPrefix .length ());
101
88
}
102
-
103
- private String getUriPrefix () {
104
- return scheme + "://" ;
105
- }
106
89
}
107
90
}
0 commit comments