INT-4067: Cover empty file case in FileSplitter
JIRA: https://jira.spring.io/browse/INT-4067 When `FileSplitter` is configured with `markers = true` and file is empty, an `iterator` for file throws `IOException: Stream closed`, because we close the `buffer` just after the first `readLine()` attempt, but still return `true` from the first `hasNext()` call where the `this.sof` and `this.eof` are `true` for markers. Add logic to mark internal splitter `iterator` as `done` where we don't have content and still in `sof` state.
This commit is contained in:
committed by
Gary Russell
parent
2090aade05
commit
b9e51088d6
@@ -185,6 +185,9 @@ public class FileSplitter extends AbstractMessageSplitter {
|
||||
if (!ready) {
|
||||
if (this.markers) {
|
||||
this.eof = true;
|
||||
if (this.sof) {
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
bufferedReader.close();
|
||||
}
|
||||
|
||||
@@ -204,6 +204,32 @@ public class FileSplitterTests {
|
||||
assertEquals(2, fileMarker.getLineCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkersEmptyFile() throws IOException {
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
FileSplitter splitter = new FileSplitter(true, true);
|
||||
splitter.setOutputChannel(outputChannel);
|
||||
File file = File.createTempFile("empty", ".txt");
|
||||
splitter.handleMessage(new GenericMessage<File>(file));
|
||||
Message<?> received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertNull(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(0, fileMarker.getLineCount());
|
||||
|
||||
received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(0, fileMarker.getLineCount());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableIntegration
|
||||
@ImportResource("classpath:org/springframework/integration/file/splitter/FileSplitterTests-context.xml")
|
||||
|
||||
Reference in New Issue
Block a user