private byte[] extractRelevantValues(Cursor cursor,String[] settings){
  final int settingsCount=settings.length;
  byte[][] values=new byte[settingsCount * 2][];
  if (!cursor.moveToFirst()) {
    Log.e(TAG,"Couldn't read from the cursor");
    return new byte[0];
  }
  int totalSize=0;
  int backedUpSettingIndex=0;
  Map<String,String> cachedEntries=new HashMap<String,String>();
  for (int i=0; i < settingsCount; i++) {
    String key=settings[i];
    String value=cachedEntries.remove(key);
    if (value == null) {
      while (!cursor.isAfterLast()) {
        String cursorKey=cursor.getString(COLUMN_NAME);
        String cursorValue=cursor.getString(COLUMN_VALUE);
        cursor.moveToNext();
        if (key.equals(cursorKey)) {
          value=cursorValue;
          break;
        }
        cachedEntries.put(cursorKey,cursorValue);
      }
    }
    if (value == null) {
      continue;
    }
    byte[] keyBytes=key.getBytes();
    totalSize+=INTEGER_BYTE_COUNT + keyBytes.length;
    values[backedUpSettingIndex * 2]=keyBytes;
    byte[] valueBytes=value.getBytes();
    totalSize+=INTEGER_BYTE_COUNT + valueBytes.length;
    values[backedUpSettingIndex * 2 + 1]=valueBytes;
    backedUpSettingIndex++;
    if (DEBUG) {
      Log.d(TAG,"Backed up setting: " + key + "="+ value);
    }
  }
  byte[] result=new byte[totalSize];
  int pos=0;
  final int keyValuePairCount=backedUpSettingIndex * 2;
  for (int i=0; i < keyValuePairCount; i++) {
    pos=writeInt(result,pos,values[i].length);
    pos=writeBytes(result,pos,values[i]);
  }
  return result;
}

private byte [ ] extractRelevantValues ( Cursor cursor , String [ ] settings ) { final int settingsCount = settings . length ; byte [ ] [ ] values = new byte [ settingsCount * 2 ] [ ] ; if ( ! cursor . moveToFirst ( ) ) { Log . e ( TAG , "Couldn't read from the cursor" ) ; return new byte [ 0 ] ; } int totalSize = 0 ; int backedUpSettingIndex = 0 ; Map < String , String > cachedEntries = new HashMap < String , String > ( ) ; for ( int i = 0 ; i < settingsCount ; i ++ ) { String key = settings [ i ] ; String value = cachedEntries . remove ( key ) ; if ( value == null ) { while ( ! cursor . isAfterLast ( ) ) { String cursorKey = cursor . getString ( COLUMN_NAME ) ; String cursorValue = cursor . getString ( COLUMN_VALUE ) ; cursor . moveToNext ( ) ; if ( key . equals ( cursorKey ) ) { value = cursorValue ; break ; } cachedEntries . put ( cursorKey , cursorValue ) ; } } if ( value == null ) { continue ; } byte [ ] keyBytes = key . getBytes ( ) ; totalSize += INTEGER_BYTE_COUNT + keyBytes . length ; values [ backedUpSettingIndex * 2 ] = keyBytes ; byte [ ] valueBytes = value . getBytes ( ) ; totalSize += INTEGER_BYTE_COUNT + valueBytes . length ; values [ backedUpSettingIndex * 2 + 1 ] = valueBytes ; backedUpSettingIndex ++ ; if ( DEBUG ) { Log . d ( TAG , "Backed up setting: " + key + "=" + value ) ; } } byte [ ] result = new byte [ totalSize ] ; int pos = 0 ; final int keyValuePairCount = backedUpSettingIndex * 2 ; for ( int i = 0 ; i < keyValuePairCount ; i ++ ) { pos = writeInt ( result , pos , values [ i ] . length ) ; pos = writeBytes ( result , pos , values [ i ] ) ; } return result ; }
given a cursor and a set of keys , extract the required keys and values and write them to a byte array .
