PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/UniversalImageLoader/src/com/nostra13/universalimageloader/core/download/URLConnectionImageDownloader.java

https://github.com/rashedulkabir/Android-Universal-Image-Loader
Java | 33 lines | 22 code | 6 blank | 5 comment | 0 complexity | e12e595a91bebd6e9fd0809ab1991a70 MD5 | raw file
 1package com.nostra13.universalimageloader.core.download;
 2
 3import java.io.BufferedInputStream;
 4import java.io.IOException;
 5import java.io.InputStream;
 6import java.net.URI;
 7import java.net.URLConnection;
 8
 9import com.nostra13.universalimageloader.core.assist.FlushedInputStream;
10
11/**
12 * Default implementation of ImageDownloader. Uses {@link URLConnection} for image stream retrieving.
13 * 
14 * @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
15 */
16public class URLConnectionImageDownloader extends ImageDownloader {
17
18	private int connectTimeout;
19	private int readTimeout;
20
21	public URLConnectionImageDownloader(int connectTimeout, int readTimeout) {
22		this.connectTimeout = connectTimeout;
23		this.readTimeout = readTimeout;
24	}
25
26	@Override
27	public InputStream getStreamFromNetwork(URI imageUri) throws IOException {
28		URLConnection conn = imageUri.toURL().openConnection();
29		conn.setConnectTimeout(connectTimeout);
30		conn.setReadTimeout(readTimeout);
31		return new FlushedInputStream(new BufferedInputStream(conn.getInputStream()));
32	}
33}