[PATCH] Introduce LineParserException for CSV file parsing
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 16 18:34:03 CEST 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1405528408 -7200
# Node ID 9342d7fe0ee716fc67128a98211f88de85e028d3
# Parent 01ad09af0975522f68597df8cea0aafb445824a0
Introduce LineParserException for CSV file parsing.
diff -r 01ad09af0975 -r 9342d7fe0ee7 backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java Wed Jul 16 17:09:02 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java Wed Jul 16 18:33:28 2014 +0200
@@ -42,8 +42,17 @@
public static final String START_META_CHAR = "#";
public static final String SEPERATOR_CHAR = ";";
+ public static class LineParserException extends Exception {
+ public LineParserException() {
+ }
- protected abstract void handleLine(int lineNum, String line);
+ public LineParserException(String msg) {
+ super(msg);
+ }
+ } // class LineParserException
+
+
+ protected abstract void handleLine(int lineNum, String line) throws LineParserException;
protected abstract void reset();
@@ -88,8 +97,9 @@
handleLine(lineNum++, line);
}
- }
- finally {
+ } catch (LineParserException lpe) {
+ log.error("Error while parsing file '" + file + "'", lpe);
+ } finally {
if (in != null) {
in.close();
}
diff -r 01ad09af0975 -r 9342d7fe0ee7 backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadLSParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadLSParser.java Wed Jul 16 17:09:02 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadLSParser.java Wed Jul 16 18:33:28 2014 +0200
@@ -116,7 +116,7 @@
@Override
- protected void handleLine(int lineNum, String line) {
+ protected void handleLine(int lineNum, String line) throws LineParserException {
if (line.startsWith(START_META_CHAR)) {
handleMetaLine(stripMetaLine(line));
}
@@ -126,22 +126,20 @@
}
- protected void handleMetaLine(String line) {
+ protected void handleMetaLine(String line) throws LineParserException {
if (handleMetaUnit(line)) {
return;
}
- else if (handleMetaFraction(line)) {
+ if (handleMetaFraction(line)) {
return;
}
- else if (handleMetaFractionName(line)) {
+ if (handleMetaFractionName(line)) {
return;
}
- else if (handleColumnNames(line)) {
+ if (handleColumnNames(line)) {
return;
}
- else {
- log.warn("SLLSP: Unknown meta line: '" + line + "'");
- }
+ log.warn("SLLSP: Unknown meta line: '" + line + "'");
}
@@ -221,7 +219,7 @@
}
- public boolean handleColumnNames(String line) {
+ public boolean handleColumnNames(String line) throws LineParserException {
Matcher m = META_COLUMN_NAMES.matcher(line);
if (m.matches()) {
@@ -229,8 +227,7 @@
// 'Fluss-km', 'Hinweise' and at least one data column required
if (columnNames.length < 3) {
- log.error("SLLSP: missing columns.");
- return true;
+ throw new LineParserException("SLLSP: missing columns.");
}
initializeSedimentLoadLSs();
More information about the Dive4Elements-commits
mailing list