summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/BrowserBackupAgent.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2010-05-03 17:23:01 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2010-05-03 17:23:01 -0700
commitfbbd2aced9ace1d063ad166d96a605446a9d2f7e (patch)
tree3e81e7b3183415ea4746ea11201d0bcce3d44dc6 /src/com/android/browser/BrowserBackupAgent.java
parent1ff2c0df2ec8db9aa558ef1f3948ac5f3bd9d6cd (diff)
parent2ceb570ad3b37fca2169ea9f453984cebf8c372c (diff)
downloadandroid_packages_apps_Gello-fbbd2aced9ace1d063ad166d96a605446a9d2f7e.tar.gz
android_packages_apps_Gello-fbbd2aced9ace1d063ad166d96a605446a9d2f7e.tar.bz2
android_packages_apps_Gello-fbbd2aced9ace1d063ad166d96a605446a9d2f7e.zip
merge from open-source master
Change-Id: I5dbf9446b7d4409ec843ee800c82ec06bda7c8db
Diffstat (limited to 'src/com/android/browser/BrowserBackupAgent.java')
-rw-r--r--src/com/android/browser/BrowserBackupAgent.java57
1 files changed, 40 insertions, 17 deletions
diff --git a/src/com/android/browser/BrowserBackupAgent.java b/src/com/android/browser/BrowserBackupAgent.java
index 6f6e829c..c968ce5d 100644
--- a/src/com/android/browser/BrowserBackupAgent.java
+++ b/src/com/android/browser/BrowserBackupAgent.java
@@ -84,6 +84,10 @@ public class BrowserBackupAgent extends BackupAgent {
savedVersion = in.readInt();
} catch (EOFException e) {
// It means we had no previous state; that's fine
+ } finally {
+ if (in != null) {
+ in.close();
+ }
}
// Build a flattened representation of the bookmarks table
@@ -174,6 +178,10 @@ public class BrowserBackupAgent extends BackupAgent {
} catch (IOException ioe) {
Log.w(TAG, "Bad backup data; not restoring");
crc = -1;
+ } finally {
+ if (in != null) {
+ in.close();
+ }
}
}
@@ -187,7 +195,7 @@ public class BrowserBackupAgent extends BackupAgent {
}
}
- class Bookmark {
+ static class Bookmark {
public String url;
public int visits;
public long date;
@@ -258,13 +266,18 @@ public class BrowserBackupAgent extends BackupAgent {
data.writeEntityHeader(key, toCopy);
FileInputStream in = new FileInputStream(file);
- int nRead;
- while (toCopy > 0) {
- nRead = in.read(buf, 0, CHUNK);
- data.writeEntityData(buf, nRead);
- toCopy -= nRead;
+ try {
+ int nRead;
+ while (toCopy > 0) {
+ nRead = in.read(buf, 0, CHUNK);
+ data.writeEntityData(buf, nRead);
+ toCopy -= nRead;
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
}
- in.close();
}
// Read the given file from backup to a file, calculating a CRC32 along the way
@@ -275,14 +288,18 @@ public class BrowserBackupAgent extends BackupAgent {
CRC32 crc = new CRC32();
FileOutputStream out = new FileOutputStream(file);
- while (toRead > 0) {
- int numRead = data.readEntityData(buf, 0, CHUNK);
- crc.update(buf, 0, numRead);
- out.write(buf, 0, numRead);
- toRead -= numRead;
+ try {
+ while (toRead > 0) {
+ int numRead = data.readEntityData(buf, 0, CHUNK);
+ crc.update(buf, 0, numRead);
+ out.write(buf, 0, numRead);
+ toRead -= numRead;
+ }
+ } finally {
+ if (out != null) {
+ out.close();
+ }
}
-
- out.close();
return crc.getValue();
}
@@ -291,8 +308,14 @@ public class BrowserBackupAgent extends BackupAgent {
throws IOException {
DataOutputStream out = new DataOutputStream(
new FileOutputStream(stateFile.getFileDescriptor()));
- out.writeLong(fileSize);
- out.writeLong(crc);
- out.writeInt(BACKUP_AGENT_VERSION);
+ try {
+ out.writeLong(fileSize);
+ out.writeLong(crc);
+ out.writeInt(BACKUP_AGENT_VERSION);
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
}
}