Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
2810:04eeb45df27b | 2811:8926571e47fb |
---|---|
1 package de.intevation.flys.importer.parsers; | 1 package de.intevation.flys.importer.parsers; |
2 | 2 |
3 import java.io.File; | |
4 | 3 |
5 import java.util.List; | 4 import java.math.BigDecimal; |
6 import java.util.ArrayList; | |
7 | 5 |
8 import java.io.IOException; | 6 import java.text.ParseException; |
9 import java.io.LineNumberReader; | 7 |
10 import java.io.FileInputStream; | 8 |
11 import java.io.InputStreamReader; | |
12 | 9 |
13 import org.apache.log4j.Logger; | 10 import org.apache.log4j.Logger; |
14 | 11 |
12 import de.intevation.flys.importer.ImportBedHeight; | |
15 import de.intevation.flys.importer.ImportBedHeightEpoch; | 13 import de.intevation.flys.importer.ImportBedHeightEpoch; |
14 import de.intevation.flys.importer.ImportBedHeightEpochValue; | |
16 | 15 |
17 | 16 |
18 public class BedHeightEpochParser { | 17 public class BedHeightEpochParser extends BedHeightParser { |
19 | |
20 public static final String ENCODING = "ISO-8859-1"; | |
21 | |
22 | |
23 protected List<ImportBedHeightEpoch> bedHeights; | |
24 | |
25 | 18 |
26 private static final Logger log = | 19 private static final Logger log = |
27 Logger.getLogger(BedHeightEpochParser.class); | 20 Logger.getLogger(BedHeightEpochParser.class); |
28 | 21 |
29 | 22 |
30 public BedHeightEpochParser() { | 23 |
31 bedHeights = new ArrayList<ImportBedHeightEpoch>(); | 24 @Override |
25 protected ImportBedHeight newImportBedHeight(String description) { | |
26 return new ImportBedHeightEpoch(description); | |
32 } | 27 } |
33 | 28 |
34 | 29 |
35 public List<ImportBedHeightEpoch> getBedHeights() { | 30 @Override |
36 return bedHeights; | 31 protected void handleDataLine(ImportBedHeight obj, String line) { |
37 } | 32 String[] values = line.split(SEPERATOR_CHAR); |
38 | 33 |
34 if (values == null || values.length < 2 || values[0].length() == 0 || values[1].length() == 0) { | |
35 //log.warn("Skip invalid data line: " + line); | |
36 return; | |
37 } | |
39 | 38 |
40 public void parse(File file) throws IOException { | 39 try { |
41 log.info("Parsing bed height epoch file '" + file + "'"); | 40 ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( |
41 new BigDecimal(nf.parse(values[0]).doubleValue()), | |
42 new BigDecimal(nf.parse(values[1]).doubleValue()) | |
43 ); | |
42 | 44 |
43 LineNumberReader in = null; | 45 obj.addValue(value); |
44 try { | |
45 in = | |
46 new LineNumberReader( | |
47 new InputStreamReader( | |
48 new FileInputStream(file), ENCODING)); | |
49 | |
50 String line = null; | |
51 while ((line = in.readLine()) != null) { | |
52 if ((line = line.trim()).length() == 0) { | |
53 continue; | |
54 } | |
55 } | |
56 } | 46 } |
57 finally { | 47 catch (ParseException e) { |
58 if (in != null) { | 48 log.warn("Error while parsing number from data row: " + line); |
59 in.close(); | |
60 } | |
61 } | 49 } |
62 } | 50 } |
63 } | 51 } |
64 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 52 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |