Commit d229e1f4 by eguven Committed by Oliver Woodman

Add helper methods to check existence and delete ActionFiles

PiperOrigin-RevId: 239002281
parent a5616cb5
...@@ -31,13 +31,11 @@ public final class ActionFile { ...@@ -31,13 +31,11 @@ public final class ActionFile {
/* package */ static final int VERSION = 0; /* package */ static final int VERSION = 0;
private final AtomicFile atomicFile; private final AtomicFile atomicFile;
private final File actionFile;
/** /**
* @param actionFile File to be used to store and load {@link DownloadAction}s. * @param actionFile File to be used to store and load {@link DownloadAction}s.
*/ */
public ActionFile(File actionFile) { public ActionFile(File actionFile) {
this.actionFile = actionFile;
atomicFile = new AtomicFile(actionFile); atomicFile = new AtomicFile(actionFile);
} }
...@@ -48,7 +46,7 @@ public final class ActionFile { ...@@ -48,7 +46,7 @@ public final class ActionFile {
* @throws IOException If there is an error during loading. * @throws IOException If there is an error during loading.
*/ */
public DownloadAction[] load() throws IOException { public DownloadAction[] load() throws IOException {
if (!actionFile.exists()) { if (!exists()) {
return new DownloadAction[0]; return new DownloadAction[0];
} }
InputStream inputStream = null; InputStream inputStream = null;
...@@ -93,4 +91,13 @@ public final class ActionFile { ...@@ -93,4 +91,13 @@ public final class ActionFile {
} }
} }
/** Returns whether the file or its backup exists. */
public boolean exists() {
return atomicFile.exists();
}
/** Delete the action file and its backup. */
public void delete() {
atomicFile.delete();
}
} }
...@@ -52,7 +52,7 @@ public final class AtomicFile { ...@@ -52,7 +52,7 @@ public final class AtomicFile {
backupName = new File(baseName.getPath() + ".bak"); backupName = new File(baseName.getPath() + ".bak");
} }
/** Whether the file or its backup exists. */ /** Returns whether the file or its backup exists. */
public boolean exists() { public boolean exists() {
return baseName.exists() || backupName.exists(); return baseName.exists() || backupName.exists();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment