Changeset 14535 in josm
- Timestamp:
- 2018-12-09T20:06:53+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r14311 r14535 420 420 } 421 421 422 protected String detectErrorMessage(String data) { 422 /** 423 * Tries do detect an error message from given string. 424 * @param data string to analyze 425 * @return error message if detected, or null 426 * @since 14535 427 */ 428 public String detectErrorMessage(String data) { 423 429 Matcher m = HttpClient.getTomcatErrorMatcher(data); 424 430 return m.matches() ? m.group(1).replace("'", "''") : null; -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r14311 r14535 67 67 * @param downloadExecutor that will be executing the jobs 68 68 */ 69 70 69 public TMSCachedTileLoaderJob(TileLoaderListener listener, Tile tile, 71 70 ICacheAccess<String, BufferedImageCacheEntry> cache, … … 321 320 322 321 @Override 323 p rotectedString detectErrorMessage(String data) {322 public String detectErrorMessage(String data) { 324 323 Matcher m = SERVICE_EXCEPTION_PATTERN.matcher(data); 325 324 return m.matches() ? removeCdata(Utils.strip(m.group(1))) : super.detectErrorMessage(data); -
trunk/src/org/openstreetmap/josm/io/AbstractReader.java
r14119 r14535 14 14 import java.util.Map; 15 15 import java.util.Map.Entry; 16 import java.util.OptionalLong; 16 17 import java.util.function.Consumer; 17 18 … … 323 324 throw new IllegalDataException(e); 324 325 } finally { 326 OptionalLong minId = externalIdMap.values().stream().mapToLong(AbstractPrimitive::getUniqueId).min(); 327 if (minId.isPresent() && minId.getAsLong() < AbstractPrimitive.currentUniqueId()) { 328 AbstractPrimitive.advanceUniqueId(minId.getAsLong()); 329 } 325 330 progressMonitor.finishTask(); 326 331 progressMonitor.removeCancelListener(cancelListener); … … 604 609 } 605 610 611 @SuppressWarnings("unchecked") 612 private <T extends OsmPrimitive> T buildPrimitive(PrimitiveData pd) { 613 OsmPrimitive p; 614 if (pd.getUniqueId() < AbstractPrimitive.currentUniqueId()) { 615 p = pd.getType().newInstance(pd.getUniqueId(), true); 616 } else { 617 p = pd.getType().newVersionedInstance(pd.getId(), pd.getVersion()); 618 } 619 p.setVisible(pd.isVisible()); 620 p.load(pd); 621 externalIdMap.put(pd.getPrimitiveId(), p); 622 return (T) p; 623 } 624 606 625 private Node addNode(NodeData nd, NodeReader nodeReader) throws IllegalDataException { 607 Node n = new Node(nd.getId(), nd.getVersion()); 608 n.setVisible(nd.isVisible()); 609 n.load(nd); 626 Node n = buildPrimitive(nd); 610 627 nodeReader.accept(n); 611 externalIdMap.put(nd.getPrimitiveId(), n);612 628 return n; 613 629 } … … 615 631 protected final Node parseNode(double lat, double lon, CommonReader commonReader, NodeReader nodeReader) 616 632 throws IllegalDataException { 617 NodeData nd = new NodeData( );633 NodeData nd = new NodeData(0); 618 634 LatLon ll = null; 619 635 if (areLatLonDefined(lat, lon)) { … … 654 670 655 671 protected final Way parseWay(CommonReader commonReader, WayReader wayReader) throws IllegalDataException { 656 WayData wd = new WayData( );672 WayData wd = new WayData(0); 657 673 commonReader.accept(wd); 658 Way w = new Way(wd.getId(), wd.getVersion()); 659 w.setVisible(wd.isVisible()); 660 w.load(wd); 661 externalIdMap.put(wd.getPrimitiveId(), w); 674 Way w = buildPrimitive(wd); 662 675 663 676 Collection<Long> nodeIds = new ArrayList<>(); … … 672 685 673 686 protected final Relation parseRelation(CommonReader commonReader, RelationReader relationReader) throws IllegalDataException { 674 RelationData rd = new RelationData( );687 RelationData rd = new RelationData(0); 675 688 commonReader.accept(rd); 676 Relation r = new Relation(rd.getId(), rd.getVersion()); 677 r.setVisible(rd.isVisible()); 678 r.load(rd); 679 externalIdMap.put(rd.getPrimitiveId(), r); 689 Relation r = buildPrimitive(rd); 680 690 681 691 Collection<RelationMemberData> members = new ArrayList<>(); -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r14480 r14535 5 5 6 6 import java.io.BufferedReader; 7 import java.io.ByteArrayOutputStream;8 7 import java.io.Closeable; 9 8 import java.io.File; … … 245 244 */ 246 245 public byte[] getByteContent() throws IOException { 247 try (InputStream is = getInputStream()) { 248 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 249 int nRead; 250 byte[] data = new byte[8192]; 251 while ((nRead = is.read(data, 0, data.length)) != -1) { 252 buffer.write(data, 0, nRead); 253 } 254 buffer.flush(); 255 return buffer.toByteArray(); 256 } 246 return Utils.readBytesFromStream(getInputStream()); 257 247 } 258 248 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r14483 r14535 1447 1447 try { 1448 1448 ByteArrayOutputStream bout = new ByteArrayOutputStream(stream.available()); 1449 byte[] buffer = new byte[ 2048];1449 byte[] buffer = new byte[8192]; 1450 1450 boolean finished = false; 1451 1451 do { -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14533 r14535 4 4 import static org.junit.Assert.assertTrue; 5 5 6 import java.io.ByteArrayInputStream; 6 7 import java.io.IOException; 7 8 import java.net.URL; 9 import java.nio.charset.StandardCharsets; 8 10 import java.util.ArrayList; 9 11 import java.util.Collections; … … 15 17 import java.util.concurrent.TimeUnit; 16 18 19 import javax.imageio.ImageIO; 20 21 import org.apache.commons.jcs.access.CacheAccess; 17 22 import org.junit.Before; 18 23 import org.junit.Rule; … … 34 39 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 35 40 import org.openstreetmap.josm.data.imagery.Shape; 41 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob; 36 42 import org.openstreetmap.josm.data.imagery.TemplatedWMSTileSource; 43 import org.openstreetmap.josm.data.imagery.TileJobOptions; 37 44 import org.openstreetmap.josm.data.imagery.WMSEndpointTileSource; 38 45 import org.openstreetmap.josm.data.imagery.WMTSTileSource; … … 64 71 private final Set<String> workingURLs = Collections.synchronizedSet(new HashSet<>()); 65 72 73 private TMSCachedTileLoaderJob helper; 66 74 private List<String> ignoredErrors; 67 75 … … 72 80 @Before 73 81 public void before() throws IOException { 82 helper = new TMSCachedTileLoaderJob(null, null, new CacheAccess<>(null), new TileJobOptions(0, 0, null, 0), null); 74 83 ignoredErrors = TestUtils.getIgnoredErrorMessages(ImageryPreferenceTestIT.class); 75 84 } … … 82 91 } 83 92 84 private voidcheckUrl(ImageryInfo info, String url) {93 private byte[] checkUrl(ImageryInfo info, String url) { 85 94 if (url != null && !url.isEmpty() && !workingURLs.contains(url)) { 86 95 try { … … 97 106 workingURLs.add(url); 98 107 } 99 response.disconnect(); 108 try { 109 return Utils.readBytesFromStream(response.getContent()); 110 } finally { 111 response.disconnect(); 112 } 100 113 } catch (IOException e) { 101 114 addError(info, url + " -> " + e); 102 115 } 116 } 117 return new byte[0]; 118 } 119 120 private void checkLinkUrl(ImageryInfo info, String url) { 121 if (url != null && checkUrl(info, url).length == 0) { 122 addError(info, url + " -> returned empty contents"); 103 123 } 104 124 } … … 109 129 for (int i = 0; i < 3; i++) { 110 130 try { 111 checkUrl(info, tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex())); 131 String url = tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex()); 132 byte[] data = checkUrl(info, url); 133 try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { 134 if (ImageIO.read(bais) == null) { 135 addImageError(info, url, data, "did not return an image"); 136 } 137 } catch (IOException e) { 138 addImageError(info, url, data, e.toString()); 139 Logging.trace(e); 140 } 112 141 return; 113 142 } catch (IOException e) { … … 125 154 } 126 155 } 156 } 157 158 private void addImageError(ImageryInfo info, String url, byte[] data, String defaultMessage) { 159 // Check if we have received an error message 160 String error = helper.detectErrorMessage(new String(data, StandardCharsets.UTF_8)); 161 addError(info, url + " -> " + (error != null ? error : defaultMessage)); 127 162 } 128 163 … … 184 219 } 185 220 186 check Url(info, info.getAttributionImageURL());187 check Url(info, info.getAttributionLinkURL());221 checkLinkUrl(info, info.getAttributionImageURL()); 222 checkLinkUrl(info, info.getAttributionLinkURL()); 188 223 String eula = info.getEulaAcceptanceRequired(); 189 224 if (eula != null) { 190 check Url(info, eula.replaceAll("\\{lang\\}", ""));191 } 192 check Url(info, info.getPermissionReferenceURL());193 check Url(info, info.getTermsOfUseURL());225 checkLinkUrl(info, eula.replaceAll("\\{lang\\}", "")); 226 } 227 checkLinkUrl(info, info.getPermissionReferenceURL()); 228 checkLinkUrl(info, info.getTermsOfUseURL()); 194 229 195 230 try {
Note:
See TracChangeset
for help on using the changeset viewer.