Removed the close() method from ItemReader - it shadows ItemStream so use that interface if needed.

This commit is contained in:
dsyer
2008-02-05 11:33:23 +00:00
parent 4d6d29b759
commit f41487b32b
6 changed files with 32 additions and 36 deletions

View File

@@ -77,7 +77,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
LineReader reader = getReader();
Object record = "";
while (reader.getCurrentLineCount() < lineCount && record != null) {
while (reader.getPosition() < lineCount && record != null) {
record = readLine();
}
@@ -95,7 +95,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
throw new StreamException("ItemStream not open or already closed.");
}
ExecutionAttributes executionAttributes = new ExecutionAttributes();
executionAttributes.putLong(READ_STATISTICS_NAME, reader.getCurrentLineCount());
executionAttributes.putLong(READ_STATISTICS_NAME, reader.getPosition());
executionAttributes.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size());
return executionAttributes;
}
@@ -130,7 +130,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
* Skip the current line which is being processed.
*/
public void skip() {
Integer count = new Integer(getReader().getCurrentLineCount());
Integer count = new Integer(getReader().getPosition());
// we are not really thread safe so we don't need to synchronize
skippedLines.add(count);
log.debug("Skipping line in template=[" + this + "], line=" + count);
@@ -138,7 +138,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
protected String readLine() {
String line = super.readLine();
while (line != null && skippedLines.contains(new Integer(getReader().getCurrentLineCount()))) {
while (line != null && skippedLines.contains(new Integer(getReader().getPosition()))) {
line = super.readLine();
}
return line;

View File

@@ -223,7 +223,7 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
return fieldSetMapper.mapLine(tokenizedLine);
} catch (RuntimeException ex) {
// add current line count to message and re-throw
int lineCount = getReader().getCurrentLineCount();
int lineCount = getReader().getPosition();
throw new FlatFileParsingException("Parsing error at line: "+lineCount+" in resource="+path+", input=["+line+"]", ex, line,
lineCount);
}

View File

@@ -16,26 +16,17 @@
package org.springframework.batch.io.file.separator;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
/**
* @author Dave Syer
*
*/
public interface LineReader extends ItemReader {
public interface LineReader extends ItemReader, ItemStream {
/**
* @return
*/
int getCurrentLineCount();
/**
*
*/
void mark();
/**
*
*/
void reset();
int getPosition();
}

View File

@@ -27,7 +27,8 @@ import java.util.Iterator;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.reader.AbstractItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.stream.ItemStreamAdapter;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
@@ -55,7 +56,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
* @author Rob Harrop
*/
public class ResourceLineReader extends AbstractItemReader implements LineReader, ItemReader,
public class ResourceLineReader extends ItemStreamAdapter implements LineReader, ItemReader,
DisposableBean {
private static final Collection DEFAULT_COMMENTS = Collections.singleton("#");
@@ -199,9 +200,21 @@ public class ResourceLineReader extends AbstractItemReader implements LineReader
*
* @return the current line count.
*/
public int getCurrentLineCount() {
public int getPosition() {
return getState().getCurrentLineCount();
}
/**
* Mark is supported as long as this {@link ItemStream} is used in a
* single-threaded environment. The state backing the mark is a single
* counter, keeping track of the current position, so multiple threads
* cannot be accommodated.
*
* @see org.springframework.batch.item.ItemStream#isMarkSupported()
*/
public boolean isMarkSupported() {
return true;
}
/**
* Mark the state for return later with reset. Uses the read-ahead limit

View File

@@ -51,12 +51,4 @@ public interface ItemReader {
*/
Object read() throws Exception;
/**
* Close the reader, freeing any resources that may have been allocated
* since the first call to read().
*
* TODO: this is only used in sandbox?
*
*/
void close() throws StreamException;
}