]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java
Use default charset for tech type CSV parsing
[simantics/district.git] / org.simantics.district.imports / src / org / simantics / district / imports / DistrictImportUtils.java
index cad063fd5094fa9d73ad4da5012d65f093c35153..d9dac92c5586c5924fbf6fe7e1fc2796aa85d3ef 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.district.imports;
 
 import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
@@ -64,7 +66,7 @@ public class DistrictImportUtils {
     public static Map<String, Integer> readCSVHeader(Path source, CSVFormat format, boolean firstAsHeader) throws IOException {
         if (firstAsHeader)
             format = format.withFirstRecordAsHeader();
-        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+        try (CSVParser parser = format.parse(Files.newBufferedReader(source, Charset.defaultCharset()))) {
             return parser.getHeaderMap();
         }
     }
@@ -105,11 +107,16 @@ public class DistrictImportUtils {
     }
     
     public static void consumeCSV(Path source, char delim, boolean firstAsHeader, Function<CSVRecord, Boolean> consumer) throws IOException {
-        CSVFormat format = CSVFormat.newFormat(delim);
+        consumeCSV(Files.newBufferedReader(source), delim, firstAsHeader, consumer);
+    }
+
+    public static void consumeCSV(Reader reader, char delim, boolean firstAsHeader,
+            Function<CSVRecord, Boolean> consumer) throws IOException {
+        CSVFormat format = CSVFormat.newFormat(delim).withQuote('"');
         if (firstAsHeader) {
             format = format.withFirstRecordAsHeader();
         }
-        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+        try (CSVParser parser = format.parse(reader)) {
             Iterator<CSVRecord> records = parser.iterator();
             while (records.hasNext()) {
                 Boolean cont = consumer.apply(records.next());
@@ -379,6 +386,7 @@ public class DistrictImportUtils {
         int lengthIndex = model.getLengthIndex();
         int detailedGeometryIndex = model.getDetailedGeometryIndex();
         int regionIndex = model.getRegionIndex();
+        int pipeTypeIndex = model.getPipeTypeIndex();
         
         int mappingColumn = model.getComponentMappingIndex();
         int idColumn = model.getIdIndex();
@@ -472,6 +480,7 @@ public class DistrictImportUtils {
                                     writeValue(graph, row, edgeFlowAreaIndex, edge, DN.Edge_HasFlowArea);
                                     writeValue(graph, row, lengthIndex, edge, DN.Edge_HasLength);
                                     writeStringValue(graph, row, regionIndex, edge, DN.HasRegion);
+                                    writeStringValue(graph, row, pipeTypeIndex, edge, DN.Edge_HasType);
                                     writeDoubleArrayFromString(graph, row, detailedGeometryIndex, edge, DN.Edge_HasGeometry, actualTransform);
                                 }
                             }