Mar 30th, 2011, 01:24 PM
FlatFileItemReader Reading Past EOF
I'm attempting to learn how to use the FlatFileItemReader to read some data exported from my iTunes Library. When it runs, it is reading all of the file data as expected, but it seems to be attempting to read past the last record. It then issues an incorrect token count exception, saying that it was expecting 27 tokens and only found 1.
Here's the configuration for the reader...
<bean id="reader" class="org.springframework.batch.item.file.FlatFil eItemReader">
<property name="resource" value="classpath:AltNation.txt"/>
<bean class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
<bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineTokenizer">
<property name="delimiter" value="|"/>
<property name="names" value="Name, Artist, Composer, Album, Grouping, Genre, Size, Time, DiscNumber, DiscCount, TrackNumber, TrackCount, Year,DateModified, DateAdded, BitRate, SampleRate, VolumeAdjustment, Kind, Equalizer, Comments, Plays, LastPlayed, Skips, LastSkipped, MyRating, Location"/>
<bean class="org.springframework.batch.item.file.mapping .BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="ITunesItem"/>
<bean id="ITunesItem" class="org.springframework.sample.batch.example.IT unesItem" scope="prototype"/>
Do I need an empty row in the file? Some other marker of some kind?
Mar 31st, 2011, 12:59 AM
you don't need an extra-line at the end of the file, on the contrary, there mustn't be any extra line. Did you check the input file?
Mar 31st, 2011, 07:55 AM
perhaps you may want to consider implementing you own record separator policy for the input file. Since we seldom have a direct influence on the file format delivered, it may be an alternative to describe the file specifics in there.
You may want to scan the reference docs chaper 6.6.2 and the interface org.springframework.batch.item.file.separator.Reco rdSeparatorPolicy.
Mar 31st, 2011, 11:14 AM
Fixed It. Thanks!
So, just a mea culpa. As I mentioned, I noticed that my input file (an exported playlist from iTunes) was shown in the directory listing as...
Turns out that the "@", which I had not encountered before, indicates additional hidden attributes. In this case it contains information about what class in Mac OS X should handle the file; essentially, it looks like the resource fork.
Once I coped the data to a new file, the problem went away.
Thanks for your quick replies.
Tags for this Thread