use of android.app.backup.BackupDataOutput in project android_frameworks_base by DirtyUnicorns.
the class BackupDataTest method testMultiple.
public void testMultiple() throws IOException {
mFile = new File(mDirectory, "backup_multiple_test.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
for (int i = 0; i < KEYS.length; i++) {
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
}
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int count = 0;
while (bdi.readNextHeader()) {
readAndVerifyEntity(bdi, KEYS[count], DATA[count].getBytes());
count++;
}
assertEquals("four entities in this stream", KEYS.length, count);
}
use of android.app.backup.BackupDataOutput in project android_frameworks_base by AOSPA.
the class LocalTransport method getRestoreData.
@Override
public int getRestoreData(ParcelFileDescriptor outFd) {
if (mRestorePackages == null)
throw new IllegalStateException("startRestore not called");
if (mRestorePackage < 0)
throw new IllegalStateException("nextRestorePackage not called");
if (mRestoreType != RestoreDescription.TYPE_KEY_VALUE) {
throw new IllegalStateException("getRestoreData(fd) for non-key/value dataset");
}
File packageDir = new File(mRestoreSetIncrementalDir, mRestorePackages[mRestorePackage].packageName);
// The restore set is the concatenation of the individual record blobs,
// each of which is a file in the package's directory. We return the
// data in lexical order sorted by key, so that apps which use synthetic
// keys like BLOB_1, BLOB_2, etc will see the date in the most obvious
// order.
ArrayList<DecodedFilename> blobs = contentsByKey(packageDir);
if (blobs == null) {
// nextRestorePackage() ensures the dir exists, so this is an error
Log.e(TAG, "No keys for package: " + packageDir);
return TRANSPORT_ERROR;
}
// We expect at least some data if the directory exists in the first place
if (DEBUG)
Log.v(TAG, " getRestoreData() found " + blobs.size() + " key files");
BackupDataOutput out = new BackupDataOutput(outFd.getFileDescriptor());
try {
for (DecodedFilename keyEntry : blobs) {
File f = keyEntry.file;
FileInputStream in = new FileInputStream(f);
try {
int size = (int) f.length();
byte[] buf = new byte[size];
in.read(buf);
if (DEBUG)
Log.v(TAG, " ... key=" + keyEntry.key + " size=" + size);
out.writeEntityHeader(keyEntry.key, size);
out.writeEntityData(buf, size);
} finally {
in.close();
}
}
return TRANSPORT_OK;
} catch (IOException e) {
Log.e(TAG, "Unable to read backup records", e);
return TRANSPORT_ERROR;
}
}
use of android.app.backup.BackupDataOutput in project android_frameworks_base by crdroidandroid.
the class BackupDataTest method testDelete.
public void testDelete() throws IOException {
mFile = new File(mDirectory, "backup_delete_test.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
for (int i = 0; i < KEYS.length; i++) {
deleteEntity(bdo, KEYS[i]);
}
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int count = 0;
while (bdi.readNextHeader()) {
readAndVerifyDeletedEntity(bdi, KEYS[count]);
count++;
}
assertEquals("four deletes in this stream", KEYS.length, count);
}
use of android.app.backup.BackupDataOutput in project android_frameworks_base by AOSPA.
the class BackupDataTest method testSingle.
public void testSingle() throws IOException {
mFile = new File(mDirectory, "backup_mixed_sinlge.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
writeEntity(bdo, KEY1, DATA1.getBytes());
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int count = 0;
while (bdi.readNextHeader()) {
readAndVerifyEntity(bdi, KEY1, DATA1.getBytes());
count++;
}
assertEquals("only one entity in this stream", 1, count);
}
use of android.app.backup.BackupDataOutput in project android_frameworks_base by AOSPA.
the class BackupDataTest method testMixed.
public void testMixed() throws IOException {
mFile = new File(mDirectory, "backup_mixed_test.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
int i = 0;
deleteEntity(bdo, KEYS[i]);
i++;
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
i++;
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
i++;
deleteEntity(bdo, KEYS[i]);
i++;
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int out = 0;
assertTrue(bdi.readNextHeader());
readAndVerifyDeletedEntity(bdi, KEYS[out]);
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyEntity(bdi, KEYS[out], DATA[out].getBytes());
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyEntity(bdi, KEYS[out], DATA[out].getBytes());
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyDeletedEntity(bdi, KEYS[out]);
out++;
assertFalse("four items in this stream", bdi.readNextHeader());
}
Aggregations