use of io.bitsquare.storage.ResourceNotFoundException in project bitsquare by bitsquare.
the class P2PDataStorage method init.
private void init(File storageDir) {
sequenceNumberMapStorage.setNumMaxBackupFiles(5);
persistedEntryMapStorage.setNumMaxBackupFiles(1);
HashMap<ByteArray, MapValue> persistedSequenceNumberMap = sequenceNumberMapStorage.<HashMap<ByteArray, MapValue>>initAndGetPersistedWithFileName("SequenceNumberMap");
if (persistedSequenceNumberMap != null)
sequenceNumberMap = getPurgedSequenceNumberMap(persistedSequenceNumberMap);
final String storageFileName = "PersistedP2PStorageData";
File dbDir = new File(storageDir.getAbsolutePath());
if (!dbDir.exists() && !dbDir.mkdir())
log.warn("make dir failed.\ndbDir=" + dbDir.getAbsolutePath());
final File destinationFile = new File(Paths.get(storageDir.getAbsolutePath(), storageFileName).toString());
if (!destinationFile.exists()) {
try {
FileUtil.resourceToFile(storageFileName, destinationFile);
} catch (ResourceNotFoundException | IOException e) {
e.printStackTrace();
log.error("Could not copy the " + storageFileName + " resource file to the db directory.\n" + e.getMessage());
}
} else {
log.debug(storageFileName + " file exists already.");
}
HashMap<ByteArray, ProtectedStorageEntry> persisted = persistedEntryMapStorage.<HashMap<ByteArray, MapValue>>initAndGetPersistedWithFileName(storageFileName);
if (persisted != null) {
persistedMap = persisted;
map.putAll(persistedMap);
// In case another object is already listening...
map.values().stream().forEach(protectedStorageEntry -> hashMapChangedListeners.stream().forEach(e -> e.onAdded(protectedStorageEntry)));
}
}
Aggregations