Skip to content

Commit 2e6bb84

Browse files
committed
Add base64:// scheme
1 parent c28c4d9 commit 2e6bb84

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

library/src/main/java/com/nostra13/universalimageloader/core/download/ImageDownloader.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
* Implementations have to be thread-safe.
2727
*
2828
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
29-
* @author Leo Link (mr[dot]leolink[at]gmail[dot]com)
3029
* @since 1.4.0
3130
*/
3231
public interface ImageDownloader {
@@ -43,29 +42,17 @@ public interface ImageDownloader {
4342
InputStream getStream(String imageUri, Object extra) throws IOException;
4443

4544
/** 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("");
5547

5648
private String scheme;
57-
private String pattern;
49+
private String uriPrefix;
5850

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 + "://";
6654
}
6755

68-
6956
/**
7057
* Defines scheme of incoming URI
7158
*
@@ -84,24 +71,20 @@ public static Scheme ofUri(String uri) {
8471
}
8572

8673
private boolean belongsTo(String uri) {
87-
return uri.toLowerCase(Locale.US).matches(pattern);
74+
return uri.toLowerCase(Locale.US).startsWith(uriPrefix);
8875
}
8976

9077
/** Appends scheme to incoming path */
9178
public String wrap(String path) {
92-
return getUriPrefix() + path;
79+
return uriPrefix + path;
9380
}
9481

9582
/** Removed scheme part ("scheme://") from incoming URI */
9683
public String crop(String uri) {
9784
if (!belongsTo(uri)) {
9885
throw new IllegalArgumentException(String.format("URI [%1$s] doesn't have expected scheme [%2$s]", uri, scheme));
9986
}
100-
return uri.substring(getUriPrefix().length());
87+
return uri.substring(uriPrefix.length());
10188
}
102-
103-
private String getUriPrefix() {
104-
return scheme + "://";
105-
}
10689
}
10790
}

0 commit comments

Comments
 (0)