This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.
No announcement yet.
How to create FlatFileItemReader?Page Title Module
You'll have to proxy the Resource you pass the FlatFileItemReader. The reader simply calls getFile(), which is all you'll really need to deal with in your proxy (you could easily use AOP to do this) Then it's as simple as calling file.listFiles() and grabbing what should be the only entry in the returned array. That's at least the only way I can think to do it.
Since I do not know AOP that well, I tried to achieve it differently.
I created my own ClassPathResource by extending the ClassPathResource. In the getFile method of MyClassPathResource I used the logic of returning the first element from file.listFiles(). Things started working. But unfortunately I found that the FieldSet is coming empty to my FieldSetmapper object. Any idea what I can do to get past it?
That's a completely different issue. If you're even getting a FieldSet at all you were able to open the file correctly. I'm not sure how it could come back empty unless either there's an issue with the file you're using, or the tokenizer was misconfigured. Can you post the file itself and how you configured the reader?
Whenever extending the ClasssPathResource, besides overriding the getFile(), getInputStream() needs to be overridden also. It is little ambiguous. If the getInputStream() is not overridden then FieldSet gets populated in with the name of the file. There will be no data in it. It could be a bug in the ClasssPathResource.getInputStream(). I am using spring-batch-1.0.0.m5 version.
In any case, one solution of addressing the requirement I have mentioned above is to extend the ClassPathResource and override getFile() and getInputStream().