FileLoaderpublic class FileLoader extends StreamLoader This class is a concrete implementation of StreamLoader that uses a
file or asset as the source for the stream. |
Fields Summary |
---|
private String | mPath | private android.content.Context | mContext | private boolean | mIsAsset | private boolean | mAllowFileAccess |
Constructors Summary |
---|
FileLoader(String url, LoadListener loadListener, android.content.Context context, boolean asset, boolean allowFileAccess)Construct a FileLoader with the file URL specified as the content
source.
super(loadListener);
mIsAsset = asset;
mContext = context;
mAllowFileAccess = allowFileAccess;
// clean the Url
int index = url.indexOf('?");
if (mIsAsset) {
mPath = index > 0 ? URLUtil.stripAnchor(
url.substring(URLUtil.ASSET_BASE.length(), index)) :
URLUtil.stripAnchor(url.substring(
URLUtil.ASSET_BASE.length()));
} else {
mPath = index > 0 ? URLUtil.stripAnchor(
url.substring(URLUtil.FILE_BASE.length(), index)) :
URLUtil.stripAnchor(url.substring(
URLUtil.FILE_BASE.length()));
}
|
Methods Summary |
---|
protected void | buildHeaders(android.net.http.Headers headers)
// do nothing.
| public static void | requestUrl(java.lang.String url, LoadListener loadListener, android.content.Context context, boolean asset, boolean allowFileAccess)Construct a FileLoader and instruct it to start loading.
FileLoader loader = new FileLoader(url, loadListener, context, asset,
allowFileAccess);
loader.load();
| protected boolean | setupStreamAndSendStatus()
try {
if (mIsAsset) {
try {
mDataStream = mContext.getAssets().open(mPath);
} catch (java.io.FileNotFoundException ex) {
// try the rest files included in the package
mDataStream = mContext.getAssets().openNonAsset(mPath);
}
} else {
if (!mAllowFileAccess) {
mHandler.error(EventHandler.FILE_ERROR,
mContext.getString(R.string.httpErrorFileNotFound));
return false;
}
mDataStream = new FileInputStream(mPath);
mContentLength = (new File(mPath)).length();
}
mHandler.status(1, 1, 0, "OK");
} catch (java.io.FileNotFoundException ex) {
mHandler.error(
EventHandler.FILE_NOT_FOUND_ERROR,
mContext.getString(R.string.httpErrorFileNotFound) +
" " + ex.getMessage());
return false;
} catch (java.io.IOException ex) {
mHandler.error(EventHandler.FILE_ERROR,
mContext.getString(R.string.httpErrorFileNotFound) +
" " + ex.getMessage());
return false;
}
return true;
|
|