Ignore:
Timestamp:
2014-06-14T12:40:50+02:00 (10 years ago)
Author:
bastiK
Message:

reworked MirroredInputStream (renamed to CachedFile):

  • no more awkwardly open and close InputStream if you just want the underlying file (e.g. to get file inside zip file)
  • make it easier to add configuration parameters, without having endless list of parameters for the constructor (Factory style, similar to ImageProvider)

breaks plugins; see #10139

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java

    r7082 r7248  
    2525import org.openstreetmap.josm.Main;
    2626import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
    27 import org.openstreetmap.josm.io.MirroredInputStream;
     27import org.openstreetmap.josm.io.CachedFile;
    2828import org.openstreetmap.josm.tools.XmlObjectParser;
    2929import org.xml.sax.SAXException;
     
    225225    public static Collection<TaggingPreset> readAll(String source, boolean validate) throws SAXException, IOException {
    226226        Collection<TaggingPreset> tp;
     227        CachedFile cf = new CachedFile(source).setHttpAccept(PRESET_MIME_TYPES);
    227228        try (
    228             MirroredInputStream s = new MirroredInputStream(source, null, PRESET_MIME_TYPES);
    229229            // 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")
    231231        ) {
    232232            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)) {
    236236                tp = readAll(new BufferedReader(r), validate);
    237237            }
Note: See TracChangeset for help on using the changeset viewer.