Methods Summary |
---|
protected abstract void | buildHeaders(android.net.http.Headers headers)This method is called when the headers are about to be sent to the
load framework. The derived class has the opportunity to add addition
headers.
|
private void | closeStreamAndSendEndData()Close the stream and inform the EventHandler that load is complete.
if (mDataStream != null) {
try {
mDataStream.close();
} catch (IOException ex) {
// ignore.
}
}
mHandler.endData();
|
public void | handleMessage(android.os.Message msg)
if (Config.DEBUG && mHandler.isSynchronous()) {
throw new AssertionError();
}
switch(msg.what) {
case MSG_STATUS:
if (setupStreamAndSendStatus()) {
// We were able to open the stream, create the array
// to pass data to the loader
mData = new byte[8192];
sendMessage(obtainMessage(MSG_HEADERS));
}
break;
case MSG_HEADERS:
sendHeaders();
sendMessage(obtainMessage(MSG_DATA));
break;
case MSG_DATA:
if (sendData()) {
sendMessage(obtainMessage(MSG_END));
} else {
sendMessage(obtainMessage(MSG_DATA));
}
break;
case MSG_END:
closeStreamAndSendEndData();
break;
default:
super.handleMessage(msg);
break;
}
|
public void | load()Calling this method starts the load of the content for this StreamLoader.
This method simply posts a message to send the status and returns
immediately.
if (!mHandler.isSynchronous()) {
sendMessage(obtainMessage(MSG_STATUS));
} else {
// Load the stream synchronously.
if (setupStreamAndSendStatus()) {
// We were able to open the stream, create the array
// to pass data to the loader
mData = new byte[8192];
sendHeaders();
while (!sendData());
closeStreamAndSendEndData();
mHandler.loadSynchronousMessages();
}
}
|
private boolean | sendData()Read data from the stream and pass it to the EventHandler.
If an error occurs reading the stream, then an error is sent to the
EventHandler, and moves onto the next state - end of data.
if (mDataStream != null) {
try {
int amount = mDataStream.read(mData);
if (amount > 0) {
mHandler.data(mData, amount);
return false;
}
} catch (IOException ex) {
mHandler.error(EventHandler.FILE_ERROR,
ex.getMessage());
}
}
return true;
|
private void | sendHeaders()Construct the headers and pass them to the EventHandler.
Headers headers = new Headers();
if (mContentLength > 0) {
headers.setContentLength(mContentLength);
}
headers.setCacheControl(NO_STORE);
buildHeaders(headers);
mHandler.headers(headers);
|
protected abstract boolean | setupStreamAndSendStatus()This method is called when the derived class should setup mDataStream,
and call mHandler.status() to indicate that the load can occur. If it
fails to setup, it should still call status() with the error code.
|