/** * Scan the filesystem for new events. * * @return */ public boolean scanFilesystem() { Set<String> knownPaths = new HashSet<String>(); Set<String> knownNames = new HashSet<String>(); for (StoredEvent s : storedEvents) { knownPaths.add(s.getPath()); knownNames.add(s.getName()); } File eventsDir = getEventsDir(); File[] eventDirFiles = eventsDir.listFiles(); if (eventDirFiles == null) { Log.e(TAG, "Failed to obtain listing for " + eventsDir.getAbsolutePath()); return false; } else { boolean eventsAdded = false; for (File eventDirFile : eventDirFiles) { if (!knownPaths.contains(eventDirFile.getAbsolutePath())) { StoredEvent newEvent = addEventFromPath(knownNames, eventDirFile.getAbsolutePath()); if (newEvent != null) { knownPaths.add(eventDirFile.getAbsolutePath()); eventsAdded = true; Log.i(TAG, "Found " + newEvent); } } } if (eventsAdded) { updateStoredEvents(); } return eventsAdded; } }
public boolean load(StoredEvent storedEvent) { File f = new File(storedEvent.getPath()); if (!f.exists()) { return false; } FileInputStream fis = null; try { fis = new FileInputStream(f); storedEvent.setEvent(ModelMarshaller.unmarshallZip(fis)); return true; } catch (Exception e) { Log.e(TAG, "Error while loading " + storedEvent, e); return false; } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { Log.e(TAG, "Error while closing stream", e); } } } }