FileDocCategorySizeDatePackage
DataLoader.javaAPI DocAndroid 1.5 API2559Wed May 06 22:41:56 BST 2009android.webkit

DataLoader

public class DataLoader extends StreamLoader
This class is a concrete implementation of StreamLoader that uses the content supplied as a URL as the source for the stream. The mimetype optionally provided in the URL is extracted and inserted into the HTTP response headers.

Fields Summary
private String
mContentType
Constructors Summary
DataLoader(String dataUrl, LoadListener loadListener)
Constructor uses the dataURL as the source for an InputStream

param
dataUrl data: URL string optionally containing a mimetype
param
loadListener LoadListener to pass the content to

        super(loadListener);

        String url = dataUrl.substring("data:".length());
        String content;
        int commaIndex = url.indexOf(',");
        if (commaIndex != -1) {
            mContentType = url.substring(0, commaIndex);
            content = url.substring(commaIndex + 1);
        } else {
            content = url;
        }
        mDataStream = new ByteArrayInputStream(content.getBytes());
        mContentLength = content.length();
    
Methods Summary
protected voidbuildHeaders(android.net.http.Headers headers)

        if (mContentType != null) {
            headers.setContentType(mContentType);
        }
    
public static voidrequestUrl(java.lang.String url, LoadListener loadListener)
Construct a DataLoader and instruct it to start loading.

param
url data: URL string optionally containing a mimetype
param
loadListener LoadListener to pass the content to

        DataLoader loader = new DataLoader(url, loadListener);
        loader.load();
    
protected booleansetupStreamAndSendStatus()

        mHandler.status(1, 1, 0, "OK");
        return true;