Changeset 36169 in osm


Ignore:
Timestamp:
2023-10-12T21:13:32+02:00 (14 months ago)
Author:
taylor.smock
Message:

Fix #23157: Change S57osm.OSMmap to accept either a file or inputstream (patch by oobayly)

Location:
applications/editors/josm/plugins/seachart
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/seachart/jrenderpgsql/src/jrenderpgsql/JrenderPgsql.java

    r35110 r36169  
    77import java.awt.geom.Point2D;
    88import java.awt.image.BufferedImage;
    9 import java.io.BufferedReader;
     9import java.io.ByteArrayInputStream;
    1010import java.io.StringReader;
    1111import java.io.ByteArrayOutputStream;
    1212import java.io.FileOutputStream;
     13import java.nio.charset.StandardCharsets;
    1314import java.util.ArrayList;
    1415import java.util.HashMap;
     
    396397        // library where it will be parsed again.
    397398
    398         BufferedReader in = new BufferedReader(new StringReader(combinedBuf.toString()));
     399        ByteArrayInputStream in = new ByteArrayInputStream(combinedBuf.toString().getBytes(StandardCharsets.UTF_8));
    399400        map = new S57map(true);
    400401        S57osm.OSMmap(in, map, false);
     
    427428            public RuleSet ruleset() {
    428429                return RuleSet.SEAMARK;
     430            }
     431
     432            public Chart chart() {
     433              return null;
     434            }
     435
     436            public int grid() {
     437              return 0;
    429438            }
    430439        };
  • applications/editors/josm/plugins/seachart/src/s57/S57osm.java

    r35404 r36169  
    33
    44import java.io.File;
     5import java.io.InputStream;
     6import java.io.FileInputStream;
    57import java.util.ArrayList;
    68import java.util.HashMap;
     
    98100    }
    99101
    100     public static void OSMmap(File in, S57map map, boolean bb) throws Exception {
     102    public static void OSMmap(File file, S57map map, boolean bb) throws Exception {
     103        try (InputStream in = new FileInputStream(file)) {
     104          OSMmap(in, map, bb);
     105        }
     106    }
     107
     108    public static void OSMmap(InputStream in, S57map map, boolean bb) throws Exception {
     109        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
     110        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
     111        Document doc = dBuilder.parse(in);
     112
     113        OSMmap(doc, map, bb);
     114    }
     115
     116    public static void OSMmap(Document doc, S57map map, boolean bb) throws Exception {
    101117        double lat = 0;
    102118        double lon = 0;
     
    113129        map.nodes.put(4L, new Snode());
    114130
    115         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    116         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    117         Document doc = dBuilder.parse(in);
    118131        doc.getDocumentElement().normalize();
    119132        if (!doc.getDocumentElement().getNodeName().equals("osm")) {
Note: See TracChangeset for help on using the changeset viewer.