Add helper methods to check existence and delete ActionFiles

PiperOrigin-RevId: 239002281
This commit is contained in:
eguven 2019-03-18 16:40:47 +00:00 committed by Oliver Woodman
parent a5616cb552
commit d229e1f405
2 changed files with 11 additions and 4 deletions

View File

@ -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 {
* @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 {
} }
} }
/** 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();
}
} }

View File

@ -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();
} }