private Set<FileAndChecksum> findFile(Fragment fragment, java.util.Map<FileAndChecksum, List<FileAndChecksum>> fileAndChecksumMap) throws IOException { Set<FileAndChecksum> result = new HashSet<>(); for (List<FileAndChecksum> fileAndChecksums : fileAndChecksumMap.values()) { for (FileAndChecksum fileAndChecksum : fileAndChecksums) { String filePath = asMetaDataComparablePath(fileAndChecksum.getFile()); if (filePath.contains(fragment.getKey())) result.add(fileAndChecksum); } } return result; }
private List<FileAndChecksum> asFragments(File directory, List<Fragment<Downloadable>> fragments, boolean useDirectoryParent) { if(fragments == null) return null; List<FileAndChecksum> result = new ArrayList<>(); for (Fragment<Downloadable> fragment : fragments) { String key = fragment.getKey(); File target = new File(useDirectoryParent ? directory.getParentFile() : directory, key); result.add(new FileAndChecksum(target, fragment.getLatestChecksum())); } return result; }
private void putDownloadables(List<? extends Downloadable> downloadables) { for (Downloadable downloadable : downloadables) { downloadableMap.put(downloadable.getUri(), downloadable); for (Fragment<Downloadable> fragment : downloadable.getFragments()) fragmentMap.put(fragment.getKey(), fragment); } }
public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Fragment fragment = (Fragment) o; return getDownloadable().equals(fragment.getDownloadable()) && getKey().equals(fragment.getKey()); }
public long calculateRemainingDownloadSize(List<BoundingBox> boundingBoxes) { Collection<Fragment<Downloadable>> fragments = getDownloadablesFor(boundingBoxes); Collection<Downloadable> downloadables = new HashSet<>(); for (Fragment<Downloadable> fragment : fragments) { java.io.File file = createFile(fragment.getKey()); if (!file.exists()) downloadables.add(fragment.getDownloadable()); } long notExists = 0L; for (Downloadable downloadable : downloadables) { Long contentLength = downloadable.getLatestChecksum().getContentLength(); if (contentLength == null) continue; notExists += contentLength; } return notExists; }
public void downloadElevationDataFor(List<LongitudeAndLatitude> longitudeAndLatitudes, boolean waitForDownload) { Set<String> keys = new HashSet<>(); for (LongitudeAndLatitude longitudeAndLatitude : longitudeAndLatitudes) { keys.add(createFileKey(longitudeAndLatitude.longitude, longitudeAndLatitude.latitude)); } Collection<Downloadable> downloadables = new HashSet<>(); for (String key : keys) { Fragment<Downloadable> fragment = dataSource.getFragment(key); // fallback as long as .hgt is not part of the keys if (fragment == null) fragment = dataSource.getFragment(removeExtension(key)); if (fragment != null && !createFile(fragment.getKey()).exists()) downloadables.add(fragment.getDownloadable()); } Collection<Download> downloads = new HashSet<>(); for (Downloadable downloadable : downloadables) { downloads.add(download(downloadable)); } if (!downloads.isEmpty() && waitForDownload) downloadManager.waitForCompletion(downloads); }
public static FragmentType createFragmentType(Fragment fragment, Set<FileAndChecksum> fileAndChecksums) { FragmentType fragmentType = new ObjectFactory().createFragmentType(); fragmentType.setKey(fragment.getKey()); List<ChecksumType> checksumTypes = asChecksumTypes(asChecksums(fileAndChecksums)); if (checksumTypes != null) fragmentType.getChecksum().addAll(checksumTypes); return fragmentType; }
private Download download(Downloadable downloadable) { List<FileAndChecksum> fragments = new ArrayList<>(); for (Fragment otherFragments : downloadable.getFragments()) { String key = otherFragments.getKey(); // ignore fragment keys without extension which are reported by old RouteConverter releases if (key.endsWith(DOT_HGT)) fragments.add(new FileAndChecksum(createFile(key), otherFragments.getLatestChecksum())); } String uri = downloadable.getUri(); String url = getBaseUrl() + uri; return downloadManager.queueForDownload(getName() + " Elevation Tile: " + uri, url, Action.valueOf(dataSource.getAction()), new FileAndChecksum(getDirectory(), downloadable.getLatestChecksum()), fragments); }