diff flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java @ 2811:8926571e47fb

Finished importing MINFO bed heights (single and epoch). flys-backend/trunk@4225 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 13 Apr 2012 07:24:55 +0000
parents 33f40b23edd8
children 26685b846a29
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java	Thu Apr 12 12:50:49 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java	Fri Apr 13 07:24:55 2012 +0000
@@ -1,63 +1,51 @@
 package de.intevation.flys.importer.parsers;
 
-import java.io.File;
 
-import java.util.List;
-import java.util.ArrayList;
+import java.math.BigDecimal;
 
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
+import java.text.ParseException;
+
+
 
 import org.apache.log4j.Logger;
 
+import de.intevation.flys.importer.ImportBedHeight;
 import de.intevation.flys.importer.ImportBedHeightEpoch;
+import de.intevation.flys.importer.ImportBedHeightEpochValue;
 
 
-public class BedHeightEpochParser {
-
-    public static final String ENCODING = "ISO-8859-1";
-
-
-    protected List<ImportBedHeightEpoch> bedHeights;
-
+public class BedHeightEpochParser extends BedHeightParser {
 
     private static final Logger log =
         Logger.getLogger(BedHeightEpochParser.class);
 
 
-    public BedHeightEpochParser() {
-        bedHeights = new ArrayList<ImportBedHeightEpoch>();
-    }
 
-
-    public List<ImportBedHeightEpoch> getBedHeights() {
-        return bedHeights;
+    @Override
+    protected ImportBedHeight newImportBedHeight(String description) {
+        return new ImportBedHeightEpoch(description);
     }
 
 
-    public void parse(File file) throws IOException {
-        log.info("Parsing bed height epoch file '" + file + "'");
-
-        LineNumberReader in = null;
-        try {
-            in =
-                new LineNumberReader(
-                new InputStreamReader(
-                new FileInputStream(file), ENCODING));
+    @Override
+    protected void handleDataLine(ImportBedHeight obj, String line) {
+        String[] values = line.split(SEPERATOR_CHAR);
 
-            String line = null;
-            while ((line = in.readLine()) != null) {
-                if ((line = line.trim()).length() == 0) {
-                    continue;
-                }
-            }
+        if (values == null || values.length < 2 || values[0].length() == 0 || values[1].length() == 0) {
+            //log.warn("Skip invalid data line: " + line);
+            return;
         }
-        finally {
-            if (in != null) {
-                in.close();
-            }
+
+        try {
+            ImportBedHeightEpochValue value = new ImportBedHeightEpochValue(
+                new BigDecimal(nf.parse(values[0]).doubleValue()),
+                new BigDecimal(nf.parse(values[1]).doubleValue())
+            );
+
+            obj.addValue(value);
+        }
+        catch (ParseException e) {
+            log.warn("Error while parsing number from data row: " + line);
         }
     }
 }

http://dive4elements.wald.intevation.org