Changeset 14404 in josm for trunk/src/org
- Timestamp:
- 2018-11-02T21:45:21+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r14367 r14404 226 226 if (file == null) { 227 227 if (name != null && name.startsWith("resource://")) { 228 InputStream is = getClass().getResourceAsStream( 229 name.substring("resource:/".length())); 230 if (is == null) 231 throw new IOException(tr("Failed to open input stream for resource ''{0}''", name)); 228 String resourceName = name.substring("resource:/".length()); 229 InputStream is = getClass().getResourceAsStream(resourceName); 230 if (is == null) { 231 URL resource = getClass().getResource(resourceName); 232 if (resource != null) { 233 // More robust way to open stream 234 is = Utils.openStream(resource); 235 } 236 if (is == null) { 237 throw new IOException(tr("Failed to open input stream for resource ''{0}''", name)); 238 } 239 } 232 240 return is; 233 241 } else { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r14331 r14404 1166 1166 try { 1167 1167 URI uri = getSvgUniverse().loadSVG(path); 1168 if (uri == null && "jar".equals(path.getProtocol())) { 1169 URL betterPath = Utils.betterJarUrl(path); 1170 if (betterPath != null) { 1171 uri = getSvgUniverse().loadSVG(betterPath); 1172 } 1173 } 1168 1174 svg = getSvgUniverse().getDiagram(uri); 1169 } catch (SecurityException e) {1175 } catch (SecurityException | IOException e) { 1170 1176 Logging.log(Logging.LEVEL_WARN, "Unable to read SVG", e); 1171 1177 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r14371 r14404 1846 1846 try { 1847 1847 return url.openStream(); 1848 } catch (FileNotFoundException e) { 1849 // Workaround to https://bugs.openjdk.java.net/browse/JDK-4523159 1850 String urlPath = url.getPath(); 1851 if (urlPath.startsWith("file:/") && urlPath.split("!").length > 2) { 1848 } catch (FileNotFoundException | InvalidPathException e) { 1849 URL betterUrl = betterJarUrl(url); 1850 if (betterUrl != null) { 1852 1851 try { 1853 // Locate jar file 1854 int index = urlPath.lastIndexOf("!/"); 1855 Path jarFile = Paths.get(urlPath.substring("file:/".length(), index)); 1856 Path filename = jarFile.getFileName(); 1857 FileTime jarTime = Files.readAttributes(jarFile, BasicFileAttributes.class).lastModifiedTime(); 1858 // Copy it to temp directory (hopefully free of exclamation mark) if needed (missing or older jar) 1859 Path jarCopy = Paths.get(getSystemProperty("java.io.tmpdir")).resolve(filename); 1860 if (!jarCopy.toFile().exists() || 1861 Files.readAttributes(jarCopy, BasicFileAttributes.class).lastModifiedTime().compareTo(jarTime) < 0) { 1862 Files.copy(jarFile, jarCopy, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); 1863 } 1864 // Open the stream using the copy 1865 return new URL(url.getProtocol() + ':' + jarCopy.toUri().toURL().toExternalForm() + urlPath.substring(index)) 1866 .openStream(); 1852 return betterUrl.openStream(); 1867 1853 } catch (RuntimeException | IOException ex) { 1868 1854 Logging.warn(ex); … … 1876 1862 } 1877 1863 } 1864 1865 /** 1866 * Tries to build a better JAR URL if we find it concerned by a JDK bug. 1867 * @param jarUrl jar URL to test 1868 * @return potentially a better URL that won't provoke a JDK bug, or null 1869 * @throws IOException if an I/O error occurs 1870 * @since 14404 1871 */ 1872 public static URL betterJarUrl(URL jarUrl) throws IOException { 1873 // Workaround to https://bugs.openjdk.java.net/browse/JDK-4523159 1874 String urlPath = jarUrl.getPath().replace("%20", " "); 1875 if (urlPath.startsWith("file:/") && urlPath.split("!").length > 2) { 1876 // Locate jar file 1877 int index = urlPath.lastIndexOf("!/"); 1878 Path jarFile = Paths.get(urlPath.substring("file:/".length(), index)); 1879 Path filename = jarFile.getFileName(); 1880 FileTime jarTime = Files.readAttributes(jarFile, BasicFileAttributes.class).lastModifiedTime(); 1881 // Copy it to temp directory (hopefully free of exclamation mark) if needed (missing or older jar) 1882 Path jarCopy = Paths.get(getSystemProperty("java.io.tmpdir")).resolve(filename); 1883 if (!jarCopy.toFile().exists() || 1884 Files.readAttributes(jarCopy, BasicFileAttributes.class).lastModifiedTime().compareTo(jarTime) < 0) { 1885 Files.copy(jarFile, jarCopy, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); 1886 } 1887 // Return URL using the copy 1888 return new URL(jarUrl.getProtocol() + ':' + jarCopy.toUri().toURL().toExternalForm() + urlPath.substring(index)); 1889 } 1890 return null; 1891 } 1878 1892 }
Note:
See TracChangeset
for help on using the changeset viewer.