diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/separator/ResourceLineReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/separator/ResourceLineReader.java index 689882b31..d8490119b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/separator/ResourceLineReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/separator/ResourceLineReader.java @@ -139,8 +139,7 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader, } /** - * @return - * @throws IOException + * @return the next non-comment line */ private String readLine() { return getState().readLine(); @@ -209,7 +208,7 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader, /** * Mark the state for return later with reset. Uses the read-ahead limit - * from the underlying {@link BufferedReader}, which means that there is a + * from an underlying {@link BufferedReader}, which means that there is a * limit to how much data can be recovered if the mark needs to be reset. * * @see #reset() @@ -250,9 +249,6 @@ public class ResourceLineReader extends ItemStreamAdapter implements LineReader, private int markedLineCount = -1; public String readLine() { - if (reader == null) { - open(); - } String line = null; try { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/MarkFailedException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/MarkFailedException.java new file mode 100644 index 000000000..e96d6b398 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/MarkFailedException.java @@ -0,0 +1,47 @@ +/* + * Copyright 2006-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.item.exception; + + +/** + * @author Dave Syer + * + */ +public class MarkFailedException extends StreamException { + + /** + * @param message + */ + public MarkFailedException(String message) { + super(message); + } + + /** + * @param msg + * @param nested + */ + public MarkFailedException(String msg, Throwable nested) { + super(msg, nested); + } + + /** + * @param msg + * @param nested + */ + public MarkFailedException(Throwable nested) { + super(nested); + } +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/ResetFailedException.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/ResetFailedException.java new file mode 100644 index 000000000..16e83b697 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/ResetFailedException.java @@ -0,0 +1,49 @@ +/* + * Copyright 2006-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.batch.item.exception; + + +/** + * @author Dave Syer + * + */ +public class ResetFailedException extends StreamException { + + /** + * @param message + */ + public ResetFailedException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + /** + * @param msg + * @param nested + */ + public ResetFailedException(String msg, Throwable nested) { + super(msg, nested); + } + + /** + * @param msg + * @param nested + */ + public ResetFailedException(Throwable nested) { + super(nested); + } + +} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/ResourceLineReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/ResourceLineReaderTests.java index 279242d70..fa3f51525 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/ResourceLineReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/ResourceLineReaderTests.java @@ -177,6 +177,14 @@ public class ResourceLineReaderTests extends TestCase { assertEquals("1", line); } + public void testMarkAfterClose() throws Exception { + Resource resource = new ByteArrayResource("1\n# 2\n3".getBytes()); + ResourceLineReader reader = new ResourceLineReader(resource); + reader.read(); + reader.close(); + reader.mark(); + } + public void testNonDefaultRecordSeparatorPolicy() throws Exception { Resource resource = new ByteArrayResource("1\n\"4\n5\"; \n6".getBytes()); ResourceLineReader reader = new ResourceLineReader(resource); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/MarkFailedExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/MarkFailedExceptionTests.java new file mode 100644 index 000000000..b3bcac0eb --- /dev/null +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/MarkFailedExceptionTests.java @@ -0,0 +1,36 @@ +/* + * Copyright 2006-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.item.exception; + +import org.springframework.batch.io.exception.AbstractExceptionTests; + + +public class MarkFailedExceptionTests extends AbstractExceptionTests { + + public Exception getException(String msg) throws Exception { + return new MarkFailedException(msg); + } + + public Exception getException(Throwable t) throws Exception { + return new MarkFailedException(t); + } + + public Exception getException(String msg, Throwable t) throws Exception { + return new MarkFailedException(msg, t); + } + +} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/ResetFailedExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/ResetFailedExceptionTests.java new file mode 100644 index 000000000..209ac7a3c --- /dev/null +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/ResetFailedExceptionTests.java @@ -0,0 +1,36 @@ +/* + * Copyright 2006-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.item.exception; + +import org.springframework.batch.io.exception.AbstractExceptionTests; + + +public class ResetFailedExceptionTests extends AbstractExceptionTests { + + public Exception getException(String msg) throws Exception { + return new ResetFailedException(msg); + } + + public Exception getException(Throwable t) throws Exception { + return new ResetFailedException(t); + } + + public Exception getException(String msg, Throwable t) throws Exception { + return new ResetFailedException(msg, t); + } + +} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/StreamExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/StreamExceptionTests.java new file mode 100644 index 000000000..b35fa2136 --- /dev/null +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/exception/StreamExceptionTests.java @@ -0,0 +1,36 @@ +/* + * Copyright 2006-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.item.exception; + +import org.springframework.batch.io.exception.AbstractExceptionTests; + + +public class StreamExceptionTests extends AbstractExceptionTests { + + public Exception getException(String msg) throws Exception { + return new StreamException(msg); + } + + public Exception getException(Throwable t) throws Exception { + return new StreamException(t); + } + + public Exception getException(String msg, Throwable t) throws Exception { + return new StreamException(msg, t); + } + +}