Odd problem with linux code

26 views
Skip to first unread message

Aram

unread,
Jan 19, 2011, 9:05:39 PM1/19/11
to CSVChat
I have a code which is working fine in my development env (windows
vista) however when I deploy it to Linux it breaks. The problem is a
multi-line entry in the CSV file, but there are no ^M variable in it
until the end.

I have:

reader.setSkipEmptyRecords(true);
reader.setTrimWhitespace(true);
reader.setDelimiter('|');
reader.setTrimWhitespace(true);

reader.setRecordDelimiter(System.getProperty("line.separator").charAt(0));

The csv is | delimited, with ^M at the end of the record.

Here is the record in question, this is all one record

2305|Universiteit Leiden|xxxx
F9500
FSSC|LEIDEN||2300 RA|NL|Europe|Netherlands|^M

In windows the insert statement is built without issue, in Linux:

20:58:55,237 DEBUG Feed:151 - INSERT INTO `DDD` ('2305','Universiteit
Leiden','xxxx','','','','','','','0000-00-00');

Exception in thread "main" java.lang.NumberFormatException: For input
string: "FSSC"
at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:
48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at com.admin.Feed.processInput(DirectFeed.java:135)
at com.admin.Feed.main(DirectFeed.java:88)

Any ideas?

shriop

unread,
Jan 19, 2011, 9:31:25 PM1/19/11
to CSVChat
You're doing some odd things with the line separators and apparently
have some odd line separators in the file. The point of
System.getProperty("line.separator") is that it returns different
values on different operating systems. In Windows, that should return
\r\n, of which you're only grabbing \r for some odd reason. In Linux,
that should return just \n. So I would expect you to get the result
you're getting if the file is \r record delimited and has \n's in the
data of your multiline record. If this file is always going to be in
this format, so always \r record delimited and only having \n's in the
data, then just set the RecordDelimiter property to \r always instead
of having it change based on the operating system, and then it should
at least work the same in both environments.

Bruce Dunwiddie

Aram Mirzadeh

unread,
Jan 20, 2011, 12:23:23 AM1/20/11
to csv...@googlegroups.com

Oh I didn't realize that was still in there when I copied and pasted the code.

Yes that was just a test, as the problem was working in Windows and not in Linux I figured I would try it.  

I did have it set to \r as the end record.   That doesn't seem to fix the problem in linux.

Aram

--
You received this message because you are subscribed to the Google Groups "CSVChat" group.
To post to this group, send email to csv...@googlegroups.com.
To unsubscribe from this group, send email to csvchat+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/csvchat?hl=en.




--
Aram Mirzadeh
a...@TranquilPhotos.com
Phone: (631) 627-1236
Sports, Events, Fine Art Photography

Aram Mirzadeh

unread,
Jan 20, 2011, 1:16:39 AM1/20/11
to csv...@googlegroups.com

My solution -- the following patch to CsvReader.java made it work in both environments. I think CR and LF should be treated as white space anyway, so I'm going to make the change globally. 

In this case if reader.setTrimWhitespace(true) is set, then the parser will ignore \r and \n.

904c904
<                             && (currentLetter == Letters.SPACE || currentLetter == Letters.TAB )) {
---
>                             && (currentLetter == Letters.SPACE || currentLetter == Letters.TAB || currentLetter == Letters.LF || currentLetter == Letters.CR)) {

kk

unread,
Sep 6, 2012, 8:43:52 PM9/6/12
to csv...@googlegroups.com
How can I specify the tab in the constructor . 

I have used CsvReader employees = new CsvReader(fileName,'\t'); but it is not taking it . Where as when I use ',' it takes it . 

Is there a way how to specify the tab .

Thanks 
Krishna

shriop

unread,
Sep 6, 2012, 10:16:41 PM9/6/12
to csv...@googlegroups.com
That should work. What do you mean by "but it is not taking it"?

Bruce Dunwiddie
Reply all
Reply to author
Forward
0 new messages