Map<Integer, String> cacheMap = CharStreams.readLines(new InputStreamReader(is),
WriteCacheFileTask.newCacheFileLineProcessor());
is.close();
int progress = 0;
bus.post(new BuildSyncPlanProgressChangedEvent(this, 0, songs.size()));
for (Song song : songs) {
if (cacheMap.containsKey(song.getId())) {
// Wanted song is in cache, so leave as is
items.add(new Item(new File(syncDir, cacheMap.get(song.getId())),
Action.LEAVE,
song));
cacheMap.remove(song.getId());
} else {
// Wanted song is absent, so download
items.add(new Item(new File(syncDir, Utils.getDiskName(song)),
Action.DOWNLOAD,
song));
}
bus.post(new BuildSyncPlanProgressChangedEvent(this, ++progress, songs.size()));
}
// Unwanted stuff that's in the cache should be removed
for (String fileName : cacheMap.values()) {
items.add(new Item(new File(syncDir, fileName), Action.DELETE, null));