Read specific record in a flat file

403 views
Skip to first unread message

Corab500

unread,
Dec 26, 2012, 8:32:00 AM12/26/12
to bea...@googlegroups.com
Hello,


I was wondering if i can retrieve specific records in a flat file...
Explanation :
  In a flat file containing a lot of different type of record i need to extract specific one. can beanio map just the one i need and don't take in account the rest of the file ?
ex : 

RANDOMRECORDINTHEFILE
THEONEIWANT
RANDOMRECORDINTHEFILE
RANDOMRECORDINTHEFILE
ANOTHER-RECORD-THAT-I-WANT
RANDOMRECORDINTHEFILE
RANDOMRECORDINTHEFILE
THEONEIWANT
.....


I'm a new user of beanio and hope you can help me :)

Regards,

Corab

Kevin

unread,
Dec 26, 2012, 11:56:42 AM12/26/12
to bea...@googlegroups.com
Hi Corab,

Sort of.  You'll need to define records in the mapping file for identifying skipped records, but by not setting a "class" attribute, BeanIO will ignore them during unmarshalling.

Thanks,
Kevin

Corab500

unread,
Dec 27, 2012, 8:01:42 AM12/27/12
to bea...@googlegroups.com
What do you mean by define records ?

i have to define for each type of record contain in the file what identifies it ? but i don't put a class attribute ? 

Kevin

unread,
Dec 27, 2012, 8:41:10 PM12/27/12
to bea...@googlegroups.com
Yes, thats correct.  Define each record with some minimal record identifying fields and leave out the "class" attribute.

By default, any record without record identifying fields (rid="true") will always match, but I can see where that makes this request more difficult than it need be, so I'll look at allowing that to be configurable in a future release.

Thanks,
Kevin

Corab500

unread,
Dec 28, 2012, 3:35:40 AM12/28/12
to bea...@googlegroups.com
Thanks for your answer Kevin,
Just a little more question.. When i read the file beanio will only read the record with a class attribute ? so each call to read() function will retrieve in the file records that match the record's description in the mapping file that has a class attribute ? and skipped all the other

Regards

Kevin

unread,
Dec 29, 2012, 7:49:26 PM12/29/12
to bea...@googlegroups.com
Yes, that's correct.
Message has been deleted
Message has been deleted

Corab500

unread,
Jan 3, 2013, 5:15:39 AM1/3/13
to bea...@googlegroups.com
Thanks Kevin it worked perfectly.

I was wondering if i want to write an XML file can i tell beanio to write some attributes only if they are not null(empty) ?

Regards,

Corab

Kevin

unread,
Jan 3, 2013, 9:53:32 PM1/3/13
to bea...@googlegroups.com
By default, null attributes are not written out unless minOccurs="1" on the field definition.  You can see examples in section 5.7.2 of the reference guide.

Thanks,
Kevin

Corab500

unread,
Jan 4, 2013, 2:24:19 AM1/4/13
to bea...@googlegroups.com
Thanks for the answer :) I have a little other issue. when reading a file i have in one ligne the following text for example :

something | "sometext" something else | sdfsdfsdf

where | is used as separator and i have the following error :  Malformed record at line 1470619: Invalid character found outside of quoted field at line 1470619
at org.beanio.internal.parser.UnmarshallingContext.newMalformedRecordException(UnmarshallingContext.java:350)

Is there a specific property that i need to add in the parser ?

Regards

Corab500

unread,
Jan 4, 2013, 5:46:22 AM1/4/13
to bea...@googlegroups.com
And how can i also make him read an write special character like ë à ... ??

Thanks

Corab

Kevin

unread,
Jan 4, 2013, 3:19:24 PM1/4/13
to bea...@googlegroups.com
What stream format are you using?  And what parser settings have you set?

Kevin

unread,
Jan 4, 2013, 3:24:45 PM1/4/13
to bea...@googlegroups.com
BeanIO will read any unicode character from the Reader passed to it, so if you are having difficulties, it is probably in how you are creating/opening your Reader.  For example, if you are using a FileInputStream, make sure you are explicitly setting the expected character encoding.  And if you are using a FileReader, I think it will use your system's default character encoding, which may not be what you need/want.

Thanks,
Kevin
Reply all
Reply to author
Forward
0 new messages