Changeset 7248 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2014-06-14T12:40:50+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r7198 r7248 30 30 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference.MapPaintPrefHelper; 31 31 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 32 import org.openstreetmap.josm.io. MirroredInputStream;32 import org.openstreetmap.josm.io.CachedFile; 33 33 import org.openstreetmap.josm.tools.ImageProvider; 34 34 import org.openstreetmap.josm.tools.Utils; … … 228 228 229 229 private static StyleSource fromSourceEntry(SourceEntry entry) { 230 MirroredInputStream in= null;230 CachedFile cf = null; 231 231 try { 232 232 Set<String> mimes = new HashSet<>(); 233 233 mimes.addAll(Arrays.asList(XmlStyleSource.XML_STYLE_MIME_TYPES.split(", "))); 234 234 mimes.addAll(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", "))); 235 in= newMirroredInputStream(entry.url, null,Utils.join(", ", mimes));236 String zipEntryPath = in.findZipEntryPath("mapcss", "style");235 cf = new CachedFile(entry.url).setHttpAccept(Utils.join(", ", mimes)); 236 String zipEntryPath = cf.findZipEntryPath("mapcss", "style"); 237 237 if (zipEntryPath != null) { 238 238 entry.isZip = true; … … 240 240 return new MapCSSStyleSource(entry); 241 241 } 242 zipEntryPath = in.findZipEntryPath("xml", "style");242 zipEntryPath = cf.findZipEntryPath("xml", "style"); 243 243 if (zipEntryPath != null) 244 244 return new XmlStyleSource(entry); … … 248 248 return new XmlStyleSource(entry); 249 249 else { 250 try (InputStreamReader reader = new InputStreamReader( in, StandardCharsets.UTF_8)) {250 try (InputStreamReader reader = new InputStreamReader(cf.getInputStream(), StandardCharsets.UTF_8)) { 251 251 WHILE: while (true) { 252 252 int c = reader.read(); … … 272 272 Main.warn(tr("Failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString())); 273 273 Main.error(e); 274 } finally {275 Utils.close(in);276 274 } 277 275 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r7185 r7248 18 18 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 19 19 import org.openstreetmap.josm.gui.preferences.SourceEntry; 20 import org.openstreetmap.josm.io. MirroredInputStream;20 import org.openstreetmap.josm.io.CachedFile; 21 21 import org.openstreetmap.josm.tools.ImageProvider; 22 22 import org.openstreetmap.josm.tools.Utils; … … 82 82 83 83 /** 84 * Returns a new {@code MirroredInputStream} to the local file containing style source (can be a text file or an archive).85 * @return A new {@code MirroredInputStream} to the local file containing style source84 * Returns a new {@code CachedFile} to the local file containing style source (can be a text file or an archive). 85 * @return A new {@code CachedFile} to the local file containing style source 86 86 * @throws IOException if any I/O error occurs. 87 87 * @since 7081 88 88 */ 89 public abstract MirroredInputStream getMirroredInputStream() throws IOException;89 public abstract CachedFile getCachedFile() throws IOException; 90 90 91 91 /** -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7200 r7248 42 42 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.TokenMgrError; 43 43 import org.openstreetmap.josm.gui.preferences.SourceEntry; 44 import org.openstreetmap.josm.io. MirroredInputStream;44 import org.openstreetmap.josm.io.CachedFile; 45 45 import org.openstreetmap.josm.tools.CheckParameterUtil; 46 46 import org.openstreetmap.josm.tools.LanguageInfo; … … 275 275 return new ByteArrayInputStream(css.getBytes(StandardCharsets.UTF_8)); 276 276 } 277 MirroredInputStream in = getMirroredInputStream();277 CachedFile cf = getCachedFile(); 278 278 if (isZip) { 279 File file = in.getFile(); 280 Utils.close(in); 279 File file = cf.getFile(); 281 280 zipFile = new ZipFile(file, StandardCharsets.UTF_8); 282 281 zipIcons = file; … … 286 285 zipFile = null; 287 286 zipIcons = null; 288 return in;289 } 290 } 291 292 @Override 293 public MirroredInputStream getMirroredInputStream() throws IOException {294 return new MirroredInputStream(url, null,MAPCSS_STYLE_MIME_TYPES);287 return cf.getInputStream(); 288 } 289 } 290 291 @Override 292 public CachedFile getCachedFile() throws IOException { 293 return new CachedFile(url).setHttpAccept(MAPCSS_STYLE_MIME_TYPES); 295 294 } 296 295 -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r7083 r7248 29 29 import org.openstreetmap.josm.gui.mappaint.StyleSource; 30 30 import org.openstreetmap.josm.gui.preferences.SourceEntry; 31 import org.openstreetmap.josm.io. MirroredInputStream;31 import org.openstreetmap.josm.io.CachedFile; 32 32 import org.openstreetmap.josm.tools.Utils; 33 33 import org.openstreetmap.josm.tools.XmlObjectParser; … … 104 104 @Override 105 105 public InputStream getSourceInputStream() throws IOException { 106 MirroredInputStream in = getMirroredInputStream();107 InputStream zip = in.findZipEntryInputStream("xml", "style");106 CachedFile cf = getCachedFile(); 107 InputStream zip = cf.findZipEntryInputStream("xml", "style"); 108 108 if (zip != null) { 109 zipIcons = in.getFile();109 zipIcons = cf.getFile(); 110 110 return zip; 111 111 } else { 112 112 zipIcons = null; 113 return in;114 } 115 } 116 117 @Override 118 public MirroredInputStream getMirroredInputStream() throws IOException {119 return new MirroredInputStream(url, null,XML_STYLE_MIME_TYPES);113 return cf.getInputStream(); 114 } 115 } 116 117 @Override 118 public CachedFile getCachedFile() throws IOException { 119 return new CachedFile(url).setHttpAccept(XML_STYLE_MIME_TYPES); 120 120 } 121 121 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r7092 r7248 22 22 import java.io.File; 23 23 import java.io.IOException; 24 import java.io.InputStream; 24 25 import java.io.InputStreamReader; 25 26 import java.net.MalformedURLException; … … 89 90 import org.openstreetmap.josm.gui.widgets.JFileChooserManager; 90 91 import org.openstreetmap.josm.gui.widgets.JosmTextField; 91 import org.openstreetmap.josm.io. MirroredInputStream;92 import org.openstreetmap.josm.io.CachedFile; 92 93 import org.openstreetmap.josm.io.OsmTransferException; 93 94 import org.openstreetmap.josm.tools.GBC; … … 1044 1045 @Override 1045 1046 public void actionPerformed(ActionEvent e) { 1046 MirroredInputStream.cleanup(url);1047 CachedFile.cleanup(url); 1047 1048 reloadAvailableSources(url, sourceProviders); 1048 1049 } … … 1280 1281 } 1281 1282 1282 MirroredInputStream stream = newMirroredInputStream(url);1283 InputStream stream = new CachedFile(url).getInputStream(); 1283 1284 reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); 1284 1285 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r7082 r7248 25 25 import org.openstreetmap.josm.Main; 26 26 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 27 import org.openstreetmap.josm.io. MirroredInputStream;27 import org.openstreetmap.josm.io.CachedFile; 28 28 import org.openstreetmap.josm.tools.XmlObjectParser; 29 29 import org.xml.sax.SAXException; … … 225 225 public static Collection<TaggingPreset> readAll(String source, boolean validate) throws SAXException, IOException { 226 226 Collection<TaggingPreset> tp; 227 CachedFile cf = new CachedFile(source).setHttpAccept(PRESET_MIME_TYPES); 227 228 try ( 228 MirroredInputStream s = new MirroredInputStream(source, null, PRESET_MIME_TYPES);229 229 // zip may be null, but Java 7 allows it: https://blogs.oracle.com/darcy/entry/project_coin_null_try_with 230 InputStream zip = s.findZipEntryInputStream("xml", "preset")230 InputStream zip = cf.findZipEntryInputStream("xml", "preset") 231 231 ) { 232 232 if (zip != null) { 233 zipIcons = s.getFile();234 } 235 try (InputStreamReader r = new InputStreamReader(zip == null ? s: zip, StandardCharsets.UTF_8)) {233 zipIcons = cf.getFile(); 234 } 235 try (InputStreamReader r = new InputStreamReader(zip == null ? cf.getInputStream() : zip, StandardCharsets.UTF_8)) { 236 236 tp = readAll(new BufferedReader(r), validate); 237 237 }
Note:
See TracChangeset
for help on using the changeset viewer.