当前位置: 首页>>代码示例>>Java>>正文


Java BackupDataOutput.writeEntityData方法代码示例

本文整理汇总了Java中android.app.backup.BackupDataOutput.writeEntityData方法的典型用法代码示例。如果您正苦于以下问题:Java BackupDataOutput.writeEntityData方法的具体用法?Java BackupDataOutput.writeEntityData怎么用?Java BackupDataOutput.writeEntityData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.backup.BackupDataOutput的用法示例。


在下文中一共展示了BackupDataOutput.writeEntityData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeRowToBackup

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private void writeRowToBackup(Key key, byte[] blob, Journal out,
        BackupDataOutput data) throws IOException {
    String backupKey = keyToBackupKey(key);
    data.writeEntityHeader(backupKey, blob.length);
    data.writeEntityData(blob, blob.length);
    out.rows++;
    out.bytes += blob.length;
    if (VERBOSE) Log.v(TAG, "saving " + geKeyType(key) + " " + backupKey + ": " +
            getKeyName(key) + "/" + blob.length);
    if(DEBUG_PAYLOAD) {
        String encoded = Base64.encodeToString(blob, 0, blob.length, Base64.NO_WRAP);
        final int chunkSize = 1024;
        for (int offset = 0; offset < encoded.length(); offset += chunkSize) {
            int end = offset + chunkSize;
            end = Math.min(end, encoded.length());
            Log.w(TAG, "wrote " + encoded.substring(offset, end));
        }
    }
}
 
开发者ID:Phonemetra,项目名称:TurboLauncher,代码行数:20,代码来源:LauncherBackupHelper.java

示例2: backupCursor

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private void backupCursor(BackupDataOutput data,
        ContentResolver contentResolver, Cursor cursor) {
    StringBuilder backedUp = new StringBuilder();
    int idColumn = cursor.getColumnIndex(ID_COLUMN);
    while (cursor.moveToNext()) {
        int id = cursor.getInt(idColumn);
        byte[] serialized = mAdaptor.Serialize(cursor);
        try {
            data.writeEntityHeader("row_" + id, serialized.length);
            data.writeEntityData(serialized, serialized.length);
            if (backedUp.length() != 0) backedUp.append(',');
            backedUp.append(id);
        } catch (IOException e) {
            Log.e("AltidroidBackup", "cannot backup: " + id);
            e.printStackTrace();
        }
    }

    // Mark all entries that were just backed up as such
    if (backedUp.length() > 0) {
        ContentValues values = new ContentValues();
        values.put("backed_up", true);
        contentResolver.update(mUri, values, "_id IN (" + backedUp.toString() + ")", null);
    }
}
 
开发者ID:aulanov,项目名称:altidroid,代码行数:26,代码来源:DatabaseBackupHelper.java

示例3: writeData

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private void writeData(BackupDataOutput data, String value) throws IOException {
    // Create buffer stream and data output stream for our data
    ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
    DataOutputStream outWriter = new DataOutputStream(bufStream);
    // 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);
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:13,代码来源:SipProfilesHelper.java

示例4: writeData

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private void writeData(BackupDataOutput data, String value) throws IOException {
    // Create buffer stream and data output stream for our data
    ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
    DataOutputStream outWriter = new DataOutputStream(bufStream);
    // 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);
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:13,代码来源:SipSharedPreferencesHelper.java

示例5: transferIncrementalRestoreData

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private int transferIncrementalRestoreData(String packageName, ParcelFileDescriptor outputFileDescriptor)
        throws IOException, InvalidAlgorithmParameterException, InvalidKeyException {

    ParcelFileDescriptor inputFileDescriptor = buildInputFileDescriptor();
    ZipInputStream inputStream = buildInputStream(inputFileDescriptor);
    BackupDataOutput backupDataOutput = new BackupDataOutput(outputFileDescriptor.getFileDescriptor());

    Optional<ZipEntry> zipEntryOptional = seekToEntry(inputStream,
            configuration.getIncrementalBackupDirectory() + packageName);
    while (zipEntryOptional.isPresent()) {
        String fileName = new File(zipEntryOptional.get().getName()).getName();
        String blobKey = new String(Base64.decode(fileName, Base64.DEFAULT));

        byte[] backupData = Streams.readFullyNoClose(inputStream);
        backupDataOutput.writeEntityHeader(blobKey, backupData.length);
        backupDataOutput.writeEntityData(backupData, backupData.length);
        inputStream.closeEntry();

        zipEntryOptional = seekToEntry(inputStream, configuration.getIncrementalBackupDirectory() + packageName);
    }

    IoUtils.closeQuietly(inputFileDescriptor);
    IoUtils.closeQuietly(outputFileDescriptor);
    return TRANSPORT_OK;
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:26,代码来源:ContentProviderRestoreComponent.java

示例6: writeRowToBackup

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private void writeRowToBackup(String backupKey, MessageNano proto,
        BackupDataOutput data) throws IOException {
    byte[] blob = writeCheckedBytes(proto);
    data.writeEntityHeader(backupKey, blob.length);
    data.writeEntityData(blob, blob.length);
    mBackupDataWasUpdated = true;
    if (VERBOSE) Log.v(TAG, "Writing New entry " + backupKey);
}
 
开发者ID:Mr-lin930819,项目名称:SimplOS,代码行数:9,代码来源:LauncherBackupHelper.java

示例7: backupPreferences

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
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);
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:8,代码来源:MyTracksBackupAgent.java

示例8: flushBufferData

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private static void flushBufferData(BackupDataOutput paramBackupDataOutput, ByteArrayOutputStream paramByteArrayOutputStream, String paramString)
  throws IOException
{
  byte[] arrayOfByte = paramByteArrayOutputStream.toByteArray();
  paramBackupDataOutput.writeEntityHeader(paramString, arrayOfByte.length);
  paramBackupDataOutput.writeEntityData(arrayOfByte, arrayOfByte.length);
  paramByteArrayOutputStream.reset();
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:9,代码来源:VendingBackupAgent.java

示例9: writeRowToBackup

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
private void writeRowToBackup(String backupKey, MessageNano proto,
        BackupDataOutput data) throws IOException {
    byte[] blob = writeCheckedBytes(proto);
    data.writeEntityHeader(backupKey, blob.length);
    data.writeEntityData(blob, blob.length);
    if (VERBOSE) Log.v(TAG, "Writing New entry " + backupKey);
}
 
开发者ID:AndroidDeveloperLB,项目名称:LB-Launcher,代码行数:8,代码来源:LauncherBackupHelper.java

示例10: writeBackupEntity

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
void writeBackupEntity(BackupDataOutput data, ByteArrayOutputStream bufStream, String key)
        throws IOException {
    byte[] buf = bufStream.toByteArray();
    data.writeEntityHeader(key, buf.length);
    data.writeEntityData(buf, buf.length);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:7,代码来源:MultiRecordExampleAgent.java

示例11: onBackup

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
/**
 * The set of data backed up by this application is very small: just
 * two booleans and an integer.  With such a simple dataset, it's
 * easiest to simply store a copy of the backed-up data as the state
 * blob describing the last dataset backed up.  The state file
 * contents can be anything; it is private to the agent class, and
 * is never stored off-device.
 *
 * <p>One thing that an application may wish to do is tag the state
 * blob contents with a version number.  This is so that if the
 * application is upgraded, the next time it attempts to do a backup,
 * it can detect that the last backup operation was performed by an
 * older version of the agent, and might therefore require different
 * handling.
 */
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) throws IOException {
    // First, get the current data from the application's file.  This
    // may throw an IOException, but in that case something has gone
    // badly wrong with the app's data on disk, and we do not want
    // to back up garbage data.  If we just let the exception go, the
    // Backup Manager will handle it and simply skip the current
    // backup operation.
    synchronized (BackupRestoreActivity.sDataLock) {
        RandomAccessFile file = new RandomAccessFile(mDataFile, "r");
        mFilling = file.readInt();
        mAddMayo = file.readBoolean();
        mAddTomato = file.readBoolean();
    }

    // If the new state file descriptor is null, this is the first time
    // a backup is being performed, so we know we have to write the
    // data.  If there <em>is</em> a previous state blob, we want to
    // double check whether the current data is actually different from
    // our last backup, so that we can avoid transmitting redundant
    // data to the storage backend.
    boolean doBackup = (oldState == null);
    if (!doBackup) {
        doBackup = compareStateFile(oldState);
    }

    // If we decided that we do in fact need to write our dataset, go
    // ahead and do that.  The way this agent backs up the data is to
    // flatten it into a single buffer, then write that to the backup
    // transport under the single key string.
    if (doBackup) {
        ByteArrayOutputStream bufStream = new ByteArrayOutputStream();

        // We use a DataOutputStream to write structured data into
        // the buffering stream
        DataOutputStream outWriter = new DataOutputStream(bufStream);
        outWriter.writeInt(mFilling);
        outWriter.writeBoolean(mAddMayo);
        outWriter.writeBoolean(mAddTomato);

        // 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);
    }

    // Finally, in all cases, we need to write the new state blob
    writeStateFile(newState);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:68,代码来源:ExampleAgent.java

示例12: performBackup

import android.app.backup.BackupDataOutput; //导入方法依赖的package包/类
@Override
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
    Log.i(TAG, "-------------------------------------------------");
    Log.i(TAG, "--- performBackup : key =  " + backupKey);
    // State
    // oldStateFd can be null
    FileDescriptor oldStateFd = oldState != null ? oldState.getFileDescriptor() : null;
    FileDescriptor newStateFd = newState.getFileDescriptor();
    if (newStateFd == null) {
        throw new NullPointerException();
    }

    // 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();
    // out.writeLong(modified);
    // } catch (IOException e) {
    // Log.e(TAG, "Error Write State : " + e.getMessage(), e);
    // } finally {
    // try {
    // out.close();
    // outstream.close();
    // } catch (IOException e) {
    // Log.e(TAG, "Error Closing State : " + e.getMessage(), e);
    // }
    //
    // }

    Log.i(TAG, "----- performBackup End : key =  " + backupKey);
    Log.i(TAG, "-------------------------------------------------");
}
 
开发者ID:gabuzomeu,项目名称:geoPingProject,代码行数:49,代码来源:AbstractDbBackupHelper.java


注:本文中的android.app.backup.BackupDataOutput.writeEntityData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。