]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/procedure/StringIO.java
Added StringIO.readContentsWithCharset
[simantics/platform.git] / bundles / org.simantics.scl.runtime / src / org / simantics / scl / runtime / procedure / StringIO.java
index a3a25933e71898af83616b42624641a26b3c7e10..82d3a9f326f772843c086a2bc43d281f9e45c3f2 100644 (file)
@@ -27,7 +27,16 @@ public class StringIO {
             throw new RuntimeException("Encoding of the file '" + fileName + "' does not conform to " + charset + ".");
         }
     }
-    
+
+    public static String readContentsWithCharset(String charset, String fileName) throws IOException {
+        try {
+            Charset cs = Charset.forName(charset);
+            return new String(Files.readAllBytes(Paths.get(fileName)), cs);
+        } catch(MalformedInputException e) {
+            throw new RuntimeException("Encoding of the file '" + fileName + "' does not conform to " + charset + ".");
+        }
+    }
+
     public static void writeLines(String fileName, List<String> lines) throws IOException {
         BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), UTF8);
         for(String line : lines) {
@@ -44,4 +53,5 @@ public class StringIO {
         writer.write("\n");
         writer.close();
     }
+
 }