Add new methods and refactor APIs. Needed later for new classes....

This commit is contained in:
chimp1984 2020-10-01 15:02:44 -05:00
parent 7122ef0356
commit df90b2440a
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3

View file

@ -77,12 +77,17 @@ public class Storage<T extends PersistableEnvelope> {
this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler; this.corruptedDatabaseFilesHandler = corruptedDatabaseFilesHandler;
} }
@Nullable
public T getPersisted(String fileName) {
return getPersisted(new File(dir, fileName));
}
@Nullable @Nullable
public T initAndGetPersistedWithFileName(String fileName, long delay) { public T initAndGetPersistedWithFileName(String fileName, long delay) {
this.fileName = fileName; this.fileName = fileName;
storageFile = new File(dir, fileName); storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver); fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted(); return getPersisted(storageFile);
} }
@Nullable @Nullable
@ -96,7 +101,7 @@ public class Storage<T extends PersistableEnvelope> {
this.fileName = fileName; this.fileName = fileName;
storageFile = new File(dir, fileName); storageFile = new File(dir, fileName);
fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver); fileManager = new FileManager<>(dir, storageFile, delay, persistenceProtoResolver);
return getPersisted(); return getPersisted(storageFile);
} }
public void queueUpForSave() { public void queueUpForSave() {
@ -144,7 +149,7 @@ public class Storage<T extends PersistableEnvelope> {
// We do the file read on the UI thread to avoid problems from multi threading. // We do the file read on the UI thread to avoid problems from multi threading.
// Data are small and read is done only at startup, so it is no performance issue. // Data are small and read is done only at startup, so it is no performance issue.
@Nullable @Nullable
private T getPersisted() { private T getPersisted(File storageFile) {
if (storageFile.exists()) { if (storageFile.exists()) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
try { try {