Merge "Use buffered DataInputStream vs RandomAccessFile" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-11 02:24:44 +00:00
committed by Android (Google) Code Review

View File

@@ -1397,23 +1397,22 @@ public class BackupManagerService {
// Remember our ancestral dataset // Remember our ancestral dataset
mTokenFile = new File(mBaseStateDir, "ancestral"); mTokenFile = new File(mBaseStateDir, "ancestral");
try { try (DataInputStream tokenStream = new DataInputStream(new BufferedInputStream(
RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r"); new FileInputStream(mTokenFile)))) {
int version = tf.readInt(); int version = tokenStream.readInt();
if (version == CURRENT_ANCESTRAL_RECORD_VERSION) { if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
mAncestralToken = tf.readLong(); mAncestralToken = tokenStream.readLong();
mCurrentToken = tf.readLong(); mCurrentToken = tokenStream.readLong();
int numPackages = tf.readInt(); int numPackages = tokenStream.readInt();
if (numPackages >= 0) { if (numPackages >= 0) {
mAncestralPackages = new HashSet<String>(); mAncestralPackages = new HashSet<>();
for (int i = 0; i < numPackages; i++) { for (int i = 0; i < numPackages; i++) {
String pkgName = tf.readUTF(); String pkgName = tokenStream.readUTF();
mAncestralPackages.add(pkgName); mAncestralPackages.add(pkgName);
} }
} }
} }
tf.close();
} catch (FileNotFoundException fnf) { } catch (FileNotFoundException fnf) {
// Probably innocuous // Probably innocuous
Slog.v(TAG, "No ancestral data"); Slog.v(TAG, "No ancestral data");
@@ -1437,12 +1436,13 @@ public class BackupManagerService {
// If there are previous contents, parse them out then start a new // If there are previous contents, parse them out then start a new
// file to continue the recordkeeping. // file to continue the recordkeeping.
if (mEverStored.exists()) { if (mEverStored.exists()) {
RandomAccessFile temp = null; DataOutputStream temp = null;
RandomAccessFile in = null; DataInputStream in = null;
try { try {
temp = new RandomAccessFile(tempProcessedFile, "rws"); temp = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(
in = new RandomAccessFile(mEverStored, "r"); tempProcessedFile)));
in = new DataInputStream(new BufferedInputStream(new FileInputStream(mEverStored)));
// Loop until we hit EOF // Loop until we hit EOF
while (true) { while (true) {