Fixed-width input is always trimmed, regardless of trimValues setting
When reading a CSV with fixed width, white space is always trimmed. See CsvRawReader::parseFixedLine
values[i] = values[i].trim();
In my use-case, I have leading white space that should remain intact. I see several possible solutions:
- only trim trailing white space for fixed-width input
- trim white space only if 'trimValues' property is true (and perhaps make it true by default for fixed-width input)
A workaround is to use one's own reader and in there replace the first blank with a nonbreaking space:
if (line.startsWith(" "))
line = "\u00a0" + line.substring(1)
Yes, there are some variations of text files that CsvJdbc does not read correctly.
An alternative is to set the following database connection properties so that the text file has a single column named LINE:
skipLeadingLines=1
suppressHeaders=true
headerline=LINE
separator=a_string_not_in_text_file
Then select the parts of each line you are interested in using SQL. For example:
select trim(substring(line, 1, 5)) as c1, trim(substring(line, 6, 8)) as c2 from fixed