com.nostra13.universalimageloader.core.download
Class BaseImageDownloader

java.lang.Object
  extended by com.nostra13.universalimageloader.core.download.BaseImageDownloader
All Implemented Interfaces:
ImageDownloader

public class BaseImageDownloader
extends Object
implements ImageDownloader

Provides retrieving of InputStream of image by URI from network or file system or app resources.
URLConnection is used to retrieve image stream from network.

Since:
1.8.0
Author:
Sergey Tarasevich (nostra13[at]gmail[dot]com)

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.nostra13.universalimageloader.core.download.ImageDownloader
ImageDownloader.Scheme
 
Field Summary
protected static String ALLOWED_URI_CHARS
          "@#&=*+-_.,:!?()/~\'%"
protected static int BUFFER_SIZE
          32768
protected  int connectTimeout
           
protected static String CONTENT_CONTACTS_URI_PREFIX
           
protected  android.content.Context context
           
static int DEFAULT_HTTP_CONNECT_TIMEOUT
          5000
static int DEFAULT_HTTP_READ_TIMEOUT
          20000
protected static int MAX_REDIRECT_COUNT
           
protected  int readTimeout
           
 
Constructor Summary
BaseImageDownloader(android.content.Context context)
           
BaseImageDownloader(android.content.Context context, int connectTimeout, int readTimeout)
           
 
Method Summary
protected  HttpURLConnection createConnection(String url, Object extra)
          Create HTTP connection for incoming URL
 InputStream getStream(String imageUri, Object extra)
          Retrieves InputStream of image by URI.
protected  InputStream getStreamFromAssets(String imageUri, Object extra)
          Retrieves InputStream of image by URI (image is located in assets of application).
protected  InputStream getStreamFromContent(String imageUri, Object extra)
          Retrieves InputStream of image by URI (image is accessed using ContentResolver).
protected  InputStream getStreamFromDrawable(String imageUri, Object extra)
          Retrieves InputStream of image by URI (image is located in drawable resources of application).
protected  InputStream getStreamFromFile(String imageUri, Object extra)
          Retrieves InputStream of image by URI (image is located on the local file system or SD card).
protected  InputStream getStreamFromNetwork(String imageUri, Object extra)
          Retrieves InputStream of image by URI (image is located in the network).
protected  InputStream getStreamFromOtherSource(String imageUri, Object extra)
          Retrieves InputStream of image by URI from other source with unsupported scheme.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HTTP_CONNECT_TIMEOUT

public static final int DEFAULT_HTTP_CONNECT_TIMEOUT
5000

See Also:
Constant Field Values

DEFAULT_HTTP_READ_TIMEOUT

public static final int DEFAULT_HTTP_READ_TIMEOUT
20000

See Also:
Constant Field Values

BUFFER_SIZE

protected static final int BUFFER_SIZE
32768

See Also:
Constant Field Values

ALLOWED_URI_CHARS

protected static final String ALLOWED_URI_CHARS
"@#&=*+-_.,:!?()/~\'%"

See Also:
Constant Field Values

MAX_REDIRECT_COUNT

protected static final int MAX_REDIRECT_COUNT
See Also:
Constant Field Values

CONTENT_CONTACTS_URI_PREFIX

protected static final String CONTENT_CONTACTS_URI_PREFIX
See Also:
Constant Field Values

context

protected final android.content.Context context

connectTimeout

protected final int connectTimeout

readTimeout

protected final int readTimeout
Constructor Detail

BaseImageDownloader

public BaseImageDownloader(android.content.Context context)

BaseImageDownloader

public BaseImageDownloader(android.content.Context context,
                           int connectTimeout,
                           int readTimeout)
Method Detail

getStream

public InputStream getStream(String imageUri,
                             Object extra)
                      throws IOException
Description copied from interface: ImageDownloader
Retrieves InputStream of image by URI.

Specified by:
getStream in interface ImageDownloader
Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image
Throws:
IOException - if some I/O error occurs during getting image stream

getStreamFromNetwork

protected InputStream getStreamFromNetwork(String imageUri,
                                           Object extra)
                                    throws IOException
Retrieves InputStream of image by URI (image is located in the network).

Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image
Throws:
IOException - if some I/O error occurs during network request or if no InputStream could be created for URL.

createConnection

protected HttpURLConnection createConnection(String url,
                                             Object extra)
                                      throws IOException
Create HTTP connection for incoming URL

Parameters:
url - URL to connect to
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
Connection for incoming URL. Connection isn't established so it still configurable.
Throws:
IOException - if some I/O error occurs during network request or if no InputStream could be created for URL.

getStreamFromFile

protected InputStream getStreamFromFile(String imageUri,
                                        Object extra)
                                 throws IOException
Retrieves InputStream of image by URI (image is located on the local file system or SD card).

Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image
Throws:
IOException - if some I/O error occurs reading from file system

getStreamFromContent

protected InputStream getStreamFromContent(String imageUri,
                                           Object extra)
                                    throws FileNotFoundException
Retrieves InputStream of image by URI (image is accessed using ContentResolver).

Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image
Throws:
FileNotFoundException - if the provided URI could not be opened

getStreamFromAssets

protected InputStream getStreamFromAssets(String imageUri,
                                          Object extra)
                                   throws IOException
Retrieves InputStream of image by URI (image is located in assets of application).

Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image
Throws:
IOException - if some I/O error occurs file reading

getStreamFromDrawable

protected InputStream getStreamFromDrawable(String imageUri,
                                            Object extra)
Retrieves InputStream of image by URI (image is located in drawable resources of application).

Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image

getStreamFromOtherSource

protected InputStream getStreamFromOtherSource(String imageUri,
                                               Object extra)
                                        throws IOException
Retrieves InputStream of image by URI from other source with unsupported scheme. Should be overriden by successors to implement image downloading from special sources.
This method is called only if image URI has unsupported scheme. Throws UnsupportedOperationException by default.

Parameters:
imageUri - Image URI
extra - Auxiliary object which was passed to DisplayImageOptions.extraForDownloader(Object); can be null
Returns:
InputStream of image
Throws:
IOException - if some I/O error occurs
UnsupportedOperationException - if image URI has unsupported scheme(protocol)


Copyright © 2011-2014. All Rights Reserved.