comparison backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java @ 7487:e327492ba9d0

Correct r7481: use ParseException instead of IllegalArgument that was catched at wrong place.
author Tom Gottfried <tom@intevation.de>
date Thu, 31 Oct 2013 19:16:42 +0100
parents bdb12632c5f5
children 1890bd524d27
comparison
equal deleted inserted replaced
7486:6b278187ed9d 7487:e327492ba9d0
187 line = line.replace(',', '.'); 187 line = line.replace(',', '.');
188 188
189 // handle Q-lines 189 // handle Q-lines
190 if (line.startsWith("*\u001f")) { 190 if (line.startsWith("*\u001f")) {
191 BigDecimal [] data = null; 191 BigDecimal [] data = null;
192 try { 192 data = parseLineAsDouble(line, columnCount, false, true);
193 data = parseLineAsDouble(line, columnCount, false, true);
194 }
195 catch(IllegalArgumentException iae) {
196 log.error(iae.getMessage());
197 return;
198 }
199 193
200 if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines 194 if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines
201 if (kmHist1 != null && kmHist2 != null 195 if (kmHist1 != null && kmHist2 != null
202 && kmHist1.compareTo(kmHist2) < 0) { // stations descending in file 196 && kmHist1.compareTo(kmHist2) < 0) { // stations descending in file
203 BigDecimal t = minKm; minKm = maxKm; maxKm = t; 197 BigDecimal t = minKm; minKm = maxKm; maxKm = t;
334 } 328 }
335 columnHeaderChecked = true; 329 columnHeaderChecked = true;
336 } 330 }
337 331
338 BigDecimal [] data = null; 332 BigDecimal [] data = null;
339 try { 333 data = parseLineAsDouble(line, columnCount, true, false);
340 data = parseLineAsDouble(line, columnCount, true, false);
341 }
342 catch(IllegalArgumentException iae) {
343 log.error(iae.getMessage());
344 return;
345 }
346 334
347 BigDecimal kaem = data[0]; 335 BigDecimal kaem = data[0];
348 336
349 if (!kms.add(kaem)) { 337 if (!kms.add(kaem)) {
350 log.warn( 338 log.warn(
507 private static final BigDecimal [] parseLineAsDouble( 495 private static final BigDecimal [] parseLineAsDouble(
508 String line, 496 String line,
509 int count, 497 int count,
510 boolean bStation, 498 boolean bStation,
511 boolean bParseEmptyAsZero 499 boolean bParseEmptyAsZero
512 ) { 500 ) throws ParseException {
513 String [] tokens = parseLine(line, count, bStation); 501 String [] tokens = parseLine(line, count, bStation);
514 502
515 BigDecimal [] doubles = new BigDecimal[tokens.length]; 503 BigDecimal [] doubles = new BigDecimal[tokens.length];
516 504
517 for (int i = 0; i < doubles.length; ++i) { 505 for (int i = 0; i < doubles.length; ++i) {
529 517
530 private static String [] parseLine( 518 private static String [] parseLine(
531 String line, 519 String line,
532 int tokenCount, 520 int tokenCount,
533 boolean bParseStation 521 boolean bParseStation
534 ) { 522 ) throws ParseException {
535 ArrayList<String> strings = new ArrayList<String>(); 523 ArrayList<String> strings = new ArrayList<String>();
536 524
537 if (bParseStation) { 525 if (bParseStation) {
538 if (line.length() < 8) { 526 if (line.length() < 8) {
539 throw new IllegalArgumentException("station too short"); 527 throw new IllegalArgumentException("station too short");
543 531
544 int pos = 0; 532 int pos = 0;
545 for (int i = 0; i < tokenCount; ++i) { 533 for (int i = 0; i < tokenCount; ++i) {
546 pos += 9; 534 pos += 9;
547 if (pos >= line.length()) { 535 if (pos >= line.length()) {
548 throw new IllegalArgumentException( 536 throw new ParseException(
549 "WST: number of columns is less than expected. File rejected."); 537 "WST: number of columns is less than expected. File rejected.");
550 } 538 }
551 strings.add(line.substring(pos, 539 strings.add(line.substring(pos,
552 Math.min(pos + 8, line.length()))); 540 Math.min(pos + 8, line.length())));
553 } 541 }

http://dive4elements.wald.intevation.org