* Obtain headers.
*
* @return HttpHeaders from the cached item, or null on error.
*/
public HttpHeaders getHeaders() {
HttpHeaders headers = null;
byte[] data = null;
// Get the code signing key associated with this BlackBerry WebWorks Application
CodeSigningKey codeSigningKey = CodeSigningKey.get( this );
// Check Persistent Store for existing data
PersistentObject cacheItemStore = PersistentStore.getPersistentObject( _storeKey );
// If we find an entry in the Persistent store
if( cacheItemStore != null ) {
Object cacheItemObj = null;
try {
// codeSigningKey is nullable
cacheItemObj = cacheItemStore.getContents( codeSigningKey );
} catch ( ControlledAccessException ignore ) {
// cacheItemObj remains null
}
if( cacheItemObj instanceof ByteVector ) {
ByteVector cacheItemVector = (ByteVector) cacheItemObj;
data = cacheItemVector.getArray();
}
}
if( data != null ) {
// Create InputStream
ByteArrayInputStream dataStream = new ByteArrayInputStream( data );
CacheManager.receiveLine( dataStream );
CacheManager.receiveLine( dataStream );
CacheManager.receiveLine( dataStream );
// Read headers
headers = new HttpHeaders();
String line = null;
while( true ) {
line = CacheManager.receiveLine( dataStream );
// Headers end with double CRLF
if( line.length() == 0 ) {
break;
}
try {
int indexOfColon = line.indexOf( ':' );
if( indexOfColon != -1 ) {
headers.setProperty( line.substring( 0, indexOfColon ).trim(),
line.substring( indexOfColon + 1 ).trim() );
} else {
// Drop the header
}
} catch( IndexOutOfBoundsException ignore ) {