001/* 002 * Copyright 2006-2008 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.item.file.transform; 017 018/** 019 * Exception indicating that the line size expected is different from what 020 * is expected. 021 * 022 * @author Lucas Ward 023 * @author Michael Minella 024 * @since 1.1 025 */ 026@SuppressWarnings("serial") 027public class IncorrectLineLengthException extends FlatFileFormatException { 028 029 private int actualLength; 030 private int expectedLength; 031 032 /** 033 * @param message the message for this exception. 034 * @param expectedLength int containing the length that was expected. 035 * @param actualLength int containing the actual length. 036 * @param input the {@link String} that contained the contents that caused 037 * the exception to be thrown. 038 * 039 * @since 2.2.6 040 */ 041 public IncorrectLineLengthException(String message, int expectedLength, int actualLength, String input) { 042 super(message, input); 043 this.expectedLength = expectedLength; 044 this.actualLength = actualLength; 045 } 046 047 /** 048 * @param message the message for this exception. 049 * @param expectedLength int containing the length that was expected. 050 * @param actualLength int containing the actual length. 051 */ 052 public IncorrectLineLengthException(String message, int expectedLength, int actualLength) { 053 super(message); 054 this.expectedLength = expectedLength; 055 this.actualLength = actualLength; 056 } 057 058 /** 059 * @param expectedLength int containing the length that was expected. 060 * @param actualLength int containing the actual length. 061 * @param input the {@link String} that contained the contents that caused 062 * the exception to be thrown. 063 064 * @since 2.2.6 065 */ 066 public IncorrectLineLengthException(int expectedLength, int actualLength, String input) { 067 super("Incorrect line length in record: expected " + expectedLength + " actual " + actualLength, input); 068 this.actualLength = actualLength; 069 this.expectedLength = expectedLength; 070 } 071 072 /** 073 * @param expectedLength int containing the length that was expected. 074 * @param actualLength int containing the actual length. 075 */ 076 public IncorrectLineLengthException(int expectedLength, int actualLength) { 077 super("Incorrect line length in record: expected " + expectedLength + " actual " + actualLength); 078 this.actualLength = actualLength; 079 this.expectedLength = expectedLength; 080 } 081 082 /** 083 * Retrieves the actual length that was recorded for this exception. 084 * 085 * @return int containing the actual length. 086 */ 087 public int getActualLength() { 088 return actualLength; 089 } 090 091 /** 092 * Retrieves the expected length that was recorded for this exception. 093 * 094 * @return int containing the expected length. 095 */ 096 public int getExpectedLength() { 097 return expectedLength; 098 } 099}