Android BackupDataOutput - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BackupDataOutput class.

This code example shows how to use the following methods:writeEntityData, writeEntityHeader
        writeStateFile(mAllPackages, newState);
    } 
     
    private static void writeEntity(BackupDataOutput data, String key, byte[] bytes)
            throws IOException { 
        data.writeEntityHeader(key, bytes.length);
        data.writeEntityData(bytes, bytes.length);
    } 
 
    // "Restore" here is a misnomer.  What we're really doing is reading back the 
    // set of app signatures associated with each backed-up app in this restore 
    // image.  We'll use those later to determine what we can legitimately restore. 
    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
            throws IOException { 
        List<ApplicationInfo> restoredApps = new ArrayList<ApplicationInfo>();
        HashMap<String, Metadata> sigMap = new HashMap<String, Metadata>();
        if (DEBUG) Slog.v(TAG, "onRestore()");
        int storedSystemVersion = -1;
 
        while (data.readNextHeader()) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
        long newChecksum = checkSummer.getValue();
        if (oldChecksum == newChecksum) {
            return oldChecksum;
        } 
        try { 
            output.writeEntityHeader(key, data.length);
            output.writeEntityData(data, data.length);
        } catch (IOException ioe) {
            // Bail 
        } 
        return newChecksum;
    } 
 
    private byte[] getDictionary() { 
        Cursor cursor = getContentResolver().query(Words.CONTENT_URI, PROJECTION,
                null, null, Words.WORD);
        if (cursor == null) return EMPTY_DATA;
        if (!cursor.moveToFirst()) {
            Log.e(TAG, "Couldn't read from the cursor");
            cursor.close();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
			 
			// Okay, we've flattened the data for transmission.  Pull it 
			// out of the buffering stream object and send it off. 
			byte[] buffer = bufStream.toByteArray();
			int len = buffer.length;
			data.writeEntityHeader(APP_DATA_KEY, len);
			data.writeEntityData(buffer, len);
		} 
		 
		//record a newState 
	} 
 
	@Override 
	public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException {
		while (data.readNextHeader()) {
			String key = data.getKey();
			int dataSize = data.getDataSize();
			 
			if (APP_DATA_KEY.equals(key)) {
				byte[] dataBuf = new byte[dataSize];
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
        long newChecksum = checkSummer.getValue();
        if (oldChecksum == newChecksum) {
            return oldChecksum;
        } 
        try { 
            output.writeEntityHeader(key, data.length);
            output.writeEntityData(data, data.length);
        } catch (IOException ioe) {
            // Bail 
        } 
        return newChecksum;
    } 
 
    private byte[] getBlacklist() { 
        Cursor cursor = getContentResolver().query(Blacklist.CONTENT_URI, PROJECTION,
                null, null, Blacklist.DEFAULT_SORT_ORDER); 
        if (cursor == null) {
            return EMPTY_DATA;
        } 
        if (!cursor.moveToFirst()) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
 
		// backup prefs 
		byte[] prefsData = getPrefsData();
		if (prefsData != null) {
			try { 
				data.writeEntityHeader(KEY_PREFERENCES, prefsData.length);
				data.writeEntityData(prefsData, prefsData.length);
			} catch (IOException e) {
				e.printStackTrace();
			} 
		} 
 
		// backup profiles 
		byte[] profilesData = getProfilesData();
		if (profilesData != null) {
			try { 
				data.writeEntityHeader(KEY_PROFILES, profilesData.length);
				data.writeEntityData(profilesData, profilesData.length);
			} catch (IOException e) {
				e.printStackTrace();

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
        // Write structured data 
        outWriter.writeUTF(value);
        // Send the data to the Backup Manager via the BackupDataOutput 
        byte[] buffer = bufStream.toByteArray();
        int len = buffer.length;
        data.writeEntityHeader(SETTINGS_BACKUP_KEY, len);
        data.writeEntityData(buffer, len);
    } 
 
    /** 
     * Read data from the input stream 
     *  
     * @param data the input stream 
     * @return the data 
     * @throws IOException I/O error 
     */ 
    private String readData(BackupDataInputStream data) throws IOException {
        String dataS;
        byte[] buf = new byte[data.size()];
        data.read(buf, 0, buf.length);
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
        // Write structured data 
        outWriter.writeUTF(value);
        // Send the data to the Backup Manager via the BackupDataOutput 
        byte[] buffer = bufStream.toByteArray();
        int len = buffer.length;
        data.writeEntityHeader(ACCOUNTS_BACKUP_KEY, len);
        data.writeEntityData(buffer, len);
    } 
 
    /** 
     * Read data from the input stream 
     *  
     * @param data the input stream 
     * @return the data 
     * @throws IOException I/O error 
     */ 
    private String readData(BackupDataInputStream data) throws IOException {
        String dataS;
        byte[] buf = new byte[data.size()];
        data.read(buf, 0, buf.length);
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
 
  private void backupPreferences(BackupDataOutput data,
      SharedPreferences preferences) throws IOException {
    PreferenceBackupHelper preferenceDumper = createPreferenceBackupHelper();
    byte[] dumpedContents = preferenceDumper.exportPreferences(preferences);
    data.writeEntityHeader(PREFERENCES_ENTITY, dumpedContents.length);
    data.writeEntityData(dumpedContents, dumpedContents.length);
  } 
 
  protected PreferenceBackupHelper createPreferenceBackupHelper() { 
    return new PreferenceBackupHelper(); 
  } 
 
  @Override 
  public void onRestore(BackupDataInput data, int appVersionCode,
      ParcelFileDescriptor newState) throws IOException {
    Log.i(Constants.TAG, "Restoring from backup");
    while (data.readNextHeader()) {
      String key = data.getKey();
      Log.d(Constants.TAG, "Restoring entity " + key);
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
 
  private void backupPreferences(BackupDataOutput data,
      SharedPreferences preferences) throws IOException {
    PreferenceBackupHelper preferenceDumper = createPreferenceBackupHelper();
    byte[] dumpedContents = preferenceDumper.exportPreferences(preferences);
    data.writeEntityHeader(PREFERENCES_ENTITY, dumpedContents.length);
    data.writeEntityData(dumpedContents, dumpedContents.length);
  } 
 
  protected PreferenceBackupHelper createPreferenceBackupHelper() { 
    return new PreferenceBackupHelper(this);
  } 
 
  @Override 
  public void onRestore(BackupDataInput data, int appVersionCode,
      ParcelFileDescriptor newState) throws IOException {
    Log.i(Constants.TAG, "Restoring from backup");
    while (data.readNextHeader()) {
      String key = data.getKey();
      Log.d(Constants.TAG, "Restoring entity " + key);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeEntityData, writeEntityHeader
        // Doing copy 
        ByteArrayOutputStream dataCopy = copyTableAsBytes();
        if (dataCopy != null) {
            try { 
                byte[] dataBytes = dataCopy.toByteArray();
                data.writeEntityHeader(backupKey, dataBytes.length);
                data.writeEntityData(dataBytes, dataBytes.length);
                Log.i(TAG, "performBackup Entity '" + backupKey + "' size=" + dataBytes.length);
            } catch (IOException e) {
                Log.e(TAG, "Error during Backup Data : " + e.getMessage(), e);
            } 
        } 
 
        // Write State 
        // FileOutputStream outstream = new 
        // FileOutputStream(newState.getFileDescriptor()); 
        // DataOutputStream out = new DataOutputStream(outstream); 
        // try { 
        // long modified = System.currentTimeMillis(); // 
        // mDataFile.lastModified(); 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android BackupDataOutput Questions & Answers:

See Code Examples for Android BackupDataOutput Methods: