@@ -55,7 +55,7 @@ public class BaseImageDownloader implements ImageDownloader {
55
55
/** {@value} */
56
56
protected static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%" ;
57
57
58
- private static final int MAX_REDIRECT_COUNT = 5 ;
58
+ protected static final int MAX_REDIRECT_COUNT = 5 ;
59
59
60
60
private static final String ERROR_UNSUPPORTED_SCHEME = "UIL doesn't support scheme(protocol) by default [%s]. "
61
61
+ "You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))" ;
@@ -104,26 +104,34 @@ public InputStream getStream(String imageUri, Object extra) throws IOException {
104
104
* DisplayImageOptions.extraForDownloader(Object)}; can be null
105
105
* @return {@link InputStream} of image
106
106
* @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
107
- * URI .
107
+ * URL .
108
108
*/
109
109
protected InputStream getStreamFromNetwork (String imageUri , Object extra ) throws IOException {
110
- HttpURLConnection conn = connectTo (imageUri );
110
+ HttpURLConnection conn = createConnection (imageUri );
111
111
112
112
int redirectCount = 0 ;
113
113
while (conn .getResponseCode () / 100 == 3 && redirectCount < MAX_REDIRECT_COUNT ) {
114
- conn = connectTo (conn .getHeaderField ("Location" ));
114
+ conn = createConnection (conn .getHeaderField ("Location" ));
115
115
redirectCount ++;
116
116
}
117
117
118
118
return new BufferedInputStream (conn .getInputStream (), BUFFER_SIZE );
119
119
}
120
120
121
- private HttpURLConnection connectTo (String url ) throws IOException {
121
+ /**
122
+ * Create {@linkplain HttpURLConnection HTTP connection} for incoming URL
123
+ *
124
+ * @param url URL to connect to
125
+ * @return {@linkplain HttpURLConnection Connection} for incoming URL. Connection isn't established so it still
126
+ * configurable.
127
+ * @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
128
+ * URL.
129
+ */
130
+ protected HttpURLConnection createConnection (String url ) throws IOException {
122
131
String encodedUrl = Uri .encode (url , ALLOWED_URI_CHARS );
123
132
HttpURLConnection conn = (HttpURLConnection ) new URL (encodedUrl ).openConnection ();
124
133
conn .setConnectTimeout (connectTimeout );
125
134
conn .setReadTimeout (readTimeout );
126
- conn .connect ();
127
135
return conn ;
128
136
}
129
137
0 commit comments