diff --git a/seachart/jrenderpgsql/src/jrenderpgsql/JrenderPgsql.java b/seachart/jrenderpgsql/src/jrenderpgsql/JrenderPgsql.java
index 0040df3..02d270a 100644
--- a/seachart/jrenderpgsql/src/jrenderpgsql/JrenderPgsql.java
+++ b/seachart/jrenderpgsql/src/jrenderpgsql/JrenderPgsql.java
@@ -6,10 +6,11 @@ import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.geom.Point2D;
 import java.awt.image.BufferedImage;
-import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.StringReader;
 import java.io.ByteArrayOutputStream;
 import java.io.FileOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -395,7 +396,7 @@ public final class JrenderPgsql {
         // The pseudo OSM file is now complete, and we feed it to the S57
         // library where it will be parsed again.
 
-        BufferedReader in = new BufferedReader(new StringReader(combinedBuf.toString()));
+        ByteArrayInputStream in = new ByteArrayInputStream(combinedBuf.toString().getBytes(StandardCharsets.UTF_8));
         map = new S57map(true);
         S57osm.OSMmap(in, map, false);
         in.close();
@@ -427,6 +428,14 @@ public final class JrenderPgsql {
             public RuleSet ruleset() {
                 return RuleSet.SEAMARK;
             }
+
+            public Chart chart() {
+              return null;
+            }
+
+            public int grid() {
+              return 0;
+            }
         };
 
         // invoke renderer, and write file to disk
diff --git a/seachart/src/s57/S57osm.java b/seachart/src/s57/S57osm.java
index 839f34e..0f50583 100644
--- a/seachart/src/s57/S57osm.java
+++ b/seachart/src/s57/S57osm.java
@@ -2,6 +2,8 @@
 package s57;
 
 import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -97,7 +99,21 @@ public final class S57osm { // OSM to S57 Object/Attribute and Object/Primitive
         return;
     }
 
-    public static void OSMmap(File in, S57map map, boolean bb) throws Exception {
+    public static void OSMmap(File file, S57map map, boolean bb) throws Exception {
+        try (InputStream in = new FileInputStream(file)) {
+          OSMmap(in, map, bb);
+        }
+    }
+
+    public static void OSMmap(InputStream in, S57map map, boolean bb) throws Exception {
+        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+        Document doc = dBuilder.parse(in);
+
+        OSMmap(doc, map, bb);
+    }
+
+    public static void OSMmap(Document doc, S57map map, boolean bb) throws Exception {
         double lat = 0;
         double lon = 0;
         long id = 0;
@@ -112,9 +128,6 @@ public final class S57osm { // OSM to S57 Object/Attribute and Object/Primitive
         map.nodes.put(3L, new Snode());
         map.nodes.put(4L, new Snode());
 
-        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-        Document doc = dBuilder.parse(in);
         doc.getDocumentElement().normalize();
         if (!doc.getDocumentElement().getNodeName().equals("osm")) {
             System.err.println("OSM file format error");
