BATCH-2092: Added access to line input when an exception is thrown
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
* @author Lucas Ward
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public abstract class AbstractLineTokenizer implements LineTokenizer {
|
||||
|
||||
@@ -121,7 +122,7 @@ public abstract class AbstractLineTokenizer implements LineTokenizer {
|
||||
return fieldSetFactory.create(values);
|
||||
}
|
||||
else if (values.length != names.length) {
|
||||
throw new IncorrectTokenCountException(names.length, values.length);
|
||||
throw new IncorrectTokenCountException(names.length, values.length, line);
|
||||
}
|
||||
return fieldSetFactory.create(values, names);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -226,7 +226,7 @@ public class DelimitedLineTokenizer extends AbstractLineTokenizer {
|
||||
/**
|
||||
* Is the supplied character the delimiter character?
|
||||
*
|
||||
* @param chars the characters to be checked
|
||||
* @param chars the character array to be checked
|
||||
* @return <code>true</code> if the supplied character is the delimiter
|
||||
* character
|
||||
* @see DelimitedLineTokenizer#DelimitedLineTokenizer(String)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
* @author peter.zozom
|
||||
* @author Dave Syer
|
||||
* @author Lucas Ward
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class FixedLengthTokenizer extends AbstractLineTokenizer {
|
||||
|
||||
@@ -105,11 +106,11 @@ public class FixedLengthTokenizer extends AbstractLineTokenizer {
|
||||
lineLength = line.length();
|
||||
|
||||
if (lineLength < maxRange && isStrict()) {
|
||||
throw new IncorrectLineLengthException("Line is shorter than max range " + maxRange, maxRange, lineLength);
|
||||
throw new IncorrectLineLengthException("Line is shorter than max range " + maxRange, maxRange, lineLength, line);
|
||||
}
|
||||
|
||||
if (!open && lineLength > maxRange && isStrict()) {
|
||||
throw new IncorrectLineLengthException("Line is longer than max range " + maxRange, maxRange, lineLength);
|
||||
throw new IncorrectLineLengthException("Line is longer than max range " + maxRange, maxRange, lineLength, line);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2008 the original author or authors.
|
||||
* Copyright 2006-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,11 +22,23 @@ package org.springframework.batch.item.file.transform;
|
||||
* attempting to parse a line of input into tokens.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Michael Minella
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FlatFileFormatException extends RuntimeException {
|
||||
|
||||
private String input;
|
||||
|
||||
/**
|
||||
* Create a new {@link FlatFileFormatException} based on a message.
|
||||
*
|
||||
* @param message the message for this exception
|
||||
*/
|
||||
public FlatFileFormatException(String message, String input) {
|
||||
super(message);
|
||||
this.input = input;
|
||||
}
|
||||
/**
|
||||
* Create a new {@link FlatFileFormatException} based on a message.
|
||||
*
|
||||
@@ -45,4 +57,6 @@ public class FlatFileFormatException extends RuntimeException {
|
||||
public FlatFileFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public String getInput() { return input; }
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.springframework.batch.item.file.transform;
|
||||
* is expected.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Michael Minella
|
||||
* @since 1.1
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@@ -27,13 +28,31 @@ public class IncorrectLineLengthException extends FlatFileFormatException {
|
||||
|
||||
private int actualLength;
|
||||
private int expectedLength;
|
||||
|
||||
|
||||
/**
|
||||
* @since 2.2.6
|
||||
*/
|
||||
public IncorrectLineLengthException(String message, int expectedLength, int actualLength, String input) {
|
||||
super(message, input);
|
||||
this.expectedLength = expectedLength;
|
||||
this.actualLength = actualLength;
|
||||
}
|
||||
|
||||
public IncorrectLineLengthException(String message, int expectedLength, int actualLength) {
|
||||
super(message);
|
||||
this.expectedLength = expectedLength;
|
||||
this.actualLength = actualLength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 2.2.6
|
||||
*/
|
||||
public IncorrectLineLengthException(int expectedLength, int actualLength, String input) {
|
||||
super("Incorrect line length in record: expected " + expectedLength + " actual " + actualLength, input);
|
||||
this.actualLength = actualLength;
|
||||
this.expectedLength = expectedLength;
|
||||
}
|
||||
|
||||
public IncorrectLineLengthException(int expectedLength, int actualLength) {
|
||||
super("Incorrect line length in record: expected " + expectedLength + " actual " + actualLength);
|
||||
this.actualLength = actualLength;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2008 the original author or authors.
|
||||
* Copyright 2006-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ package org.springframework.batch.item.file.transform;
|
||||
* while parsing a file.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author "Michael Minella"
|
||||
* @since 1.1
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@@ -27,13 +28,28 @@ public class IncorrectTokenCountException extends FlatFileFormatException {
|
||||
|
||||
private int actualCount;
|
||||
private int expectedCount;
|
||||
|
||||
private String input;
|
||||
|
||||
public IncorrectTokenCountException(String message, int expectedCount, int actualCount, String input) {
|
||||
super(message);
|
||||
this.expectedCount = expectedCount;
|
||||
this.actualCount = actualCount;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public IncorrectTokenCountException(String message, int expectedCount, int actualCount) {
|
||||
super(message);
|
||||
this.expectedCount = expectedCount;
|
||||
this.actualCount = actualCount;
|
||||
}
|
||||
|
||||
|
||||
public IncorrectTokenCountException(int expectedCount, int actualCount, String input) {
|
||||
super("Incorrect number of tokens found in record: expected " + expectedCount + " actual " + actualCount);
|
||||
this.expectedCount = expectedCount;
|
||||
this.actualCount = actualCount;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public IncorrectTokenCountException(int expectedCount, int actualCount) {
|
||||
super("Incorrect number of tokens found in record: expected " + expectedCount + " actual " + actualCount);
|
||||
this.actualCount = actualCount;
|
||||
@@ -47,4 +63,10 @@ public class IncorrectTokenCountException extends FlatFileFormatException {
|
||||
public int getExpectedCount() {
|
||||
return expectedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the line that caused the exception
|
||||
* @since 2.2.6
|
||||
*/
|
||||
public String getInput() { return input; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user