|
1 | 1 | // License: GPL. For details, see LICENSE file.
|
2 | 2 | package org.openstreetmap.josm.plugins.mapillary.utils;
|
3 | 3 |
|
| 4 | +import java.io.IOException; |
4 | 5 | import java.time.Instant;
|
5 | 6 | import java.util.Locale;
|
| 7 | +import java.util.concurrent.CancellationException; |
6 | 8 | import java.util.concurrent.CompletableFuture;
|
7 | 9 | import java.util.function.Predicate;
|
8 | 10 | import java.util.regex.Matcher;
|
|
13 | 15 |
|
14 | 16 | import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
|
15 | 17 | import org.openstreetmap.josm.data.cache.CacheEntry;
|
| 18 | +import org.openstreetmap.josm.data.cache.ICachedLoaderListener; |
16 | 19 | import org.openstreetmap.josm.data.osm.INode;
|
17 | 20 | import org.openstreetmap.josm.data.osm.IPrimitive;
|
18 | 21 | import org.openstreetmap.josm.data.osm.IWay;
|
@@ -136,8 +139,17 @@ public static CompletableFuture<BufferedImageCacheEntry> getImage(@Nonnull INode
|
136 | 139 | }
|
137 | 140 | if (MapillaryImageUtils.isDownloadable(image)) {
|
138 | 141 | CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();
|
139 |
| - CacheUtils.submit(image, type, |
140 |
| - (entry, attributes, result) -> cacheImageFuture(image, completableFuture, entry)); |
| 142 | + CacheUtils.submit(image, type, (entry, attributes, result) -> { |
| 143 | + if (result == ICachedLoaderListener.LoadResult.SUCCESS) { |
| 144 | + cacheImageFuture(image, completableFuture, entry); |
| 145 | + } else if (result == ICachedLoaderListener.LoadResult.CANCELED) { |
| 146 | + completableFuture.completeExceptionally(new CancellationException( |
| 147 | + "Mapillary Image download was cancelled: " + MapillaryImageUtils.getKey(image))); |
| 148 | + } else { |
| 149 | + completableFuture.completeExceptionally(new IOException( |
| 150 | + "Mapillary Image could not be downloaded: " + MapillaryImageUtils.getKey(image))); |
| 151 | + } |
| 152 | + }); |
141 | 153 | return completableFuture;
|
142 | 154 | } else if (getKey(image) > 0) {
|
143 | 155 | CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();
|
|
0 commit comments