RESOLVED - issue BATCH-1225: FlatFileItemWriter does not restart in the right place

Also fixed StaxEventItemWriter
This commit is contained in:
dsyer
2009-05-22 07:36:27 +00:00
parent 6db366cf67
commit 1980412e85
6 changed files with 184 additions and 21 deletions

View File

@@ -214,7 +214,7 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
public void close() {
if (state != null) {
try {
if (footerCallback != null) {
if (footerCallback != null && state.outputBufferedWriter != null) {
footerCallback.writeFooter(state.outputBufferedWriter);
state.outputBufferedWriter.flush();
}
@@ -350,7 +350,7 @@ public class FlatFileItemWriter<T> extends ExecutionContextUserSupport implement
}
outputBufferedWriter.flush();
pos = fileChannel.position();
pos = fileChannel.position() + ((TransactionAwareBufferedWriter)outputBufferedWriter).getBufferSize();
return pos;

View File

@@ -126,6 +126,8 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
private StaxWriterCallback footerCallback;
private TransactionAwareBufferedWriter transactionAwareBufferedWriter;
public StaxEventItemWriter() {
setName(ClassUtils.getShortName(StaxEventItemWriter.class));
}
@@ -315,8 +317,9 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
try {
delegateEventWriter = outputFactory.createXMLEventWriter(new TransactionAwareBufferedWriter(
new OutputStreamWriter(os, encoding), getName()));
transactionAwareBufferedWriter = new TransactionAwareBufferedWriter(
new OutputStreamWriter(os, encoding), getName());
delegateEventWriter = outputFactory.createXMLEventWriter(transactionAwareBufferedWriter);
eventWriter = new NoStartEndDocumentStreamWriter(delegateEventWriter);
if (!restarted) {
startDocument(delegateEventWriter);
@@ -487,7 +490,7 @@ public class StaxEventItemWriter<T> extends ExecutionContextUserSupport implemen
try {
eventWriter.flush();
position = channel.position();
position = channel.position() + transactionAwareBufferedWriter.getBufferSize();
}
catch (Exception e) {
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e);

View File

@@ -81,6 +81,19 @@ public class TransactionAwareBufferedWriter extends Writer {
}
/**
* Convenience method for clients to determine if there is any unflushed
* data.
*
* @return the current size of unflushed buffered data
*/
public long getBufferSize() {
if (!transactionActive()) {
return 0L;
}
return getCurrentBuffer().length();
}
/**
* @return
*/