Ignore:
Timestamp:
2014-06-14T12:40:50+02:00 (9 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

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r7134 r7248  
    5959import org.openstreetmap.josm.Main;
    6060import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    61 import org.openstreetmap.josm.io.MirroredInputStream;
    6261import org.openstreetmap.josm.plugins.PluginHandler;
    6362import org.w3c.dom.Element;
     
    7574import com.kitfox.svg.SVGException;
    7675import com.kitfox.svg.SVGUniverse;
     76import org.openstreetmap.josm.io.CachedFile;
    7777
    7878/**
     
    533533
    534534    private static ImageResource getIfAvailableHttp(String url, ImageType type) {
    535         try (MirroredInputStream is = new MirroredInputStream(url,
    536                     new File(Main.pref.getCacheDirectory(), "images").getPath())) {
     535        CachedFile cf = new CachedFile(url)
     536                .setDestDir(new File(Main.pref.getCacheDirectory(), "images").getPath());
     537        try (InputStream is = cf.getInputStream()) {
    537538            switch (type) {
    538539            case SVG:
    539                 URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(is.getFile()).toString());
     540                URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(cf.getFile()).toString());
    540541                SVGDiagram svg = getSvgUniverse().getDiagram(uri);
    541542                return svg == null ? null : new ImageResource(svg);
     
    543544                BufferedImage img = null;
    544545                try {
    545                     img = read(Utils.fileToURL(is.getFile()), false, false);
     546                    img = read(Utils.fileToURL(cf.getFile()), false, false);
    546547                } catch (IOException e) {
    547548                    Main.warn("IOException while reading HTTP image: "+e.getMessage());
     
    800801            });
    801802
    802             try (InputStream is = new MirroredInputStream(
    803                     base + fn,
    804                     new File(Main.pref.getPreferencesDir(), "images").toString())
    805             ) {
     803            CachedFile cf = new CachedFile(base + fn).setDestDir(new File(Main.pref.getPreferencesDir(), "images").toString());
     804            try (InputStream is = cf.getInputStream()) {
    806805                parser.parse(new InputSource(is));
    807806            }
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r7193 r7248  
    1111import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.data.osm.Way;
     13import org.openstreetmap.josm.io.CachedFile;
    1314import org.openstreetmap.josm.io.IllegalDataException;
    14 import org.openstreetmap.josm.io.MirroredInputStream;
    1515import org.openstreetmap.josm.io.OsmReader;
    1616import org.openstreetmap.josm.tools.GeoPropertyIndex.GeoProperty;
     
    6767    private static void initialize() {
    6868        leftHandTrafficPolygons = new ArrayList<>();
    69         try (InputStream is = new MirroredInputStream("resource://data/left-right-hand-traffic.osm")) {
     69        try (InputStream is = new CachedFile("resource://data/left-right-hand-traffic.osm").getInputStream()) {
    7070            DataSet data = OsmReader.parseDataSet(is, null);
    7171            for (Way w : data.getWays()) {
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r7033 r7248  
    2828
    2929import org.openstreetmap.josm.Main;
    30 import org.openstreetmap.josm.io.MirroredInputStream;
     30import org.openstreetmap.josm.io.CachedFile;
    3131import org.xml.sax.Attributes;
    3232import org.xml.sax.ContentHandler;
     
    281281    public Iterable<Object> startWithValidation(final Reader in, String namespace, String schemaSource) throws SAXException {
    282282        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    283         try (InputStream mis = new MirroredInputStream(schemaSource)) {
     283        try (InputStream mis = new CachedFile(schemaSource).getInputStream()) {
    284284            Schema schema = factory.newSchema(new StreamSource(mis));
    285285            ValidatorHandler validator = schema.newValidatorHandler();
Note: See TracChangeset for help on using the changeset viewer.