diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java index 35bcee76d..8812c467d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/AbstractLineTokenizer.java @@ -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); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java index 622b8f847..62e32c23c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java @@ -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 true if the supplied character is the delimiter * character * @see DelimitedLineTokenizer#DelimitedLineTokenizer(String) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java index 7ad7600cc..4b59a67c3 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java @@ -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++) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FlatFileFormatException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FlatFileFormatException.java index c4a31c6b8..827db10b2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FlatFileFormatException.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FlatFileFormatException.java @@ -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; } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectLineLengthException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectLineLengthException.java index b7af28ecd..ce80de6bf 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectLineLengthException.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectLineLengthException.java @@ -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; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectTokenCountException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectTokenCountException.java index b8e7d0f5c..b73237837 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectTokenCountException.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/IncorrectTokenCountException.java @@ -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; } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java index eb687f0af..b4fa1068a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 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. @@ -81,6 +81,7 @@ public class DelimitedLineTokenizerTests { catch (IncorrectTokenCountException e) { assertEquals(2, e.getExpectedCount()); assertEquals(3, e.getActualCount()); + assertEquals("a,b,c", e.getInput()); } } @@ -104,6 +105,7 @@ public class DelimitedLineTokenizerTests { catch(IncorrectTokenCountException e){ assertEquals(4, e.getExpectedCount()); assertEquals(3, e.getActualCount()); + assertEquals("a,b,c", e.getInput()); } } @@ -279,6 +281,7 @@ public class DelimitedLineTokenizerTests { catch(IncorrectTokenCountException ex){ assertEquals(2, ex.getExpectedCount()); assertEquals(0, ex.getActualCount()); + assertEquals("", ex.getInput()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java index a1f4669f2..e4287a249 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java @@ -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. @@ -41,6 +41,7 @@ public class FixedLengthTokenizerTests { catch (IncorrectLineLengthException ex) { assertEquals(15, ex.getExpectedLength()); assertEquals(0, ex.getActualLength()); + assertEquals("", ex.getInput()); } } @@ -60,6 +61,7 @@ public class FixedLengthTokenizerTests { catch (IncorrectLineLengthException ex) { assertEquals(15, ex.getExpectedLength()); assertEquals(5, ex.getActualLength()); + assertEquals("12345", ex.getInput()); } } @@ -97,6 +99,7 @@ public class FixedLengthTokenizerTests { fail("Expected IncorrectLineLengthException"); } catch (IncorrectLineLengthException ex) { + assertEquals("", ex.getInput()); } } @@ -135,6 +138,7 @@ public class FixedLengthTokenizerTests { catch (IncorrectLineLengthException ex) { assertEquals(30, ex.getExpectedLength()); assertEquals(35, ex.getActualLength()); + assertEquals(line, ex.getInput()); } }