mirror of
https://github.com/androidx/media.git
synced 2025-05-16 12:09:50 +08:00
Add helper methods to check existence and delete ActionFiles
PiperOrigin-RevId: 239002281
This commit is contained in:
parent
a5616cb552
commit
d229e1f405
@ -31,13 +31,11 @@ public final class ActionFile {
|
||||
/* package */ static final int VERSION = 0;
|
||||
|
||||
private final AtomicFile atomicFile;
|
||||
private final File actionFile;
|
||||
|
||||
/**
|
||||
* @param actionFile File to be used to store and load {@link DownloadAction}s.
|
||||
*/
|
||||
public ActionFile(File actionFile) {
|
||||
this.actionFile = actionFile;
|
||||
atomicFile = new AtomicFile(actionFile);
|
||||
}
|
||||
|
||||
@ -48,7 +46,7 @@ public final class ActionFile {
|
||||
* @throws IOException If there is an error during loading.
|
||||
*/
|
||||
public DownloadAction[] load() throws IOException {
|
||||
if (!actionFile.exists()) {
|
||||
if (!exists()) {
|
||||
return new DownloadAction[0];
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public final class AtomicFile {
|
||||
backupName = new File(baseName.getPath() + ".bak");
|
||||
}
|
||||
|
||||
/** Whether the file or its backup exists. */
|
||||
/** Returns whether the file or its backup exists. */
|
||||
public boolean exists() {
|
||||
return baseName.exists() || backupName.exists();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user