@Override public Exception getException(String msg, Throwable t) throws Exception { return new FlatFileParseException(msg, t, "bar", 100); }
@Override public Exception getException(String msg) throws Exception { return new FlatFileParseException(msg, "bar"); }
private String applyRecordSeparatorPolicy(String line) throws IOException { String record = line; while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) { line = this.reader.readLine(); if (line == null) { if (StringUtils.hasText(record)) { // A record was partially complete since it hasn't ended but // the line is null throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount); } else { // Record has no text but it might still be post processed // to something (skipping preProcess since that was already // done) break; } } else { lineCount++; } record = recordSeparatorPolicy.preProcess(record) + line; } return recordSeparatorPolicy.postProcess(record); }
/** * @return string corresponding to logical record according to * {@link #setRecordSeparatorPolicy(RecordSeparatorPolicy)} (might span multiple lines in file). */ @Override protected T doRead() throws Exception { if (noInput) { return null; } String line = readLine(); if (line == null) { return null; } else { try { return lineMapper.mapLine(line, lineCount); } catch (Exception ex) { throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=[" + resource.getDescription() + "], input=[" + line + "]", ex, line, lineCount); } } }
@Test public void testLimitExceed() { try { failurePolicy.shouldSkip(new FlatFileParseException("", ""), 2); fail(); } catch (SkipLimitExceededException ex) { // expected } }
@Test public void testSkip() { assertTrue(failurePolicy.shouldSkip(new FlatFileParseException("", ""), 0)); }
public void testMessageInputLineCount() throws Exception { FlatFileParseException exception = new FlatFileParseException("foo", "bar", 100); assertEquals("foo", exception.getMessage()); assertEquals("bar", exception.getInput()); assertEquals(100, exception.getLineNumber()); }
private String applyRecordSeparatorPolicy(String line) throws IOException { String record = line; while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) { line = this.reader.readLine(); if (line == null) { if (StringUtils.hasText(record)) { // A record was partially complete since it hasn't ended but // the line is null throw new FlatFileParseException("Unexpected end of file before record complete", record, lineCount); } else { // Record has no text but it might still be post processed // to something (skipping preProcess since that was already // done) break; } } else { lineCount++; } record = recordSeparatorPolicy.preProcess(record) + line; } return recordSeparatorPolicy.postProcess(record); }
/** * @return string corresponding to logical record according to * {@link #setRecordSeparatorPolicy(RecordSeparatorPolicy)} (might span multiple lines in file). */ @Override protected T doRead() throws Exception { if (noInput) { return null; } String line = readLine(); if (line == null) { return null; } else { try { return lineMapper.mapLine(line, lineCount); } catch (Exception ex) { throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=[" + resource.getDescription() + "], input=[" + line + "]", ex, line, lineCount); } } }
@Override @SuppressWarnings("unchecked") protected T doRead() throws Exception { if (reader == null) { return null; } try { return (T) reader.read(); } catch (BeanReaderIOException ex) { throw ex.getCause(); } catch (BeanReaderException ex) { if (useSpringExceptions) { RecordContext ctx = ex.getRecordContext(); if (ctx != null) { throw new FlatFileParseException(ex.getMessage(), ex, ctx.getRecordText(), ctx.getLineNumber()); } else { throw new FlatFileParseException(ex.getMessage(), ex, null, 0); } } else { throw ex; } } }