Skip to content

Commit

Permalink
CAMEL-11595: Fixed the reader premature closure by competing threads
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger committed Jun 10, 2018
1 parent 353acb4 commit cab92ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Expand Up @@ -116,15 +116,13 @@ protected CPS initialValue() {
} }
} }


HeaderRowProcessor headerRowProcessor = new HeaderRowProcessor();
CPS settings = parserSettings.get();
settings.setProcessor(headerRowProcessor);
P parser = createParser(settings);
// univocity-parsers is responsible for closing the reader, even in case of error
Reader reader = new InputStreamReader(stream, getCharsetName(exchange)); Reader reader = new InputStreamReader(stream, getCharsetName(exchange));
try { return unmarshaller.unmarshal(reader, parser, headerRowProcessor);
HeaderRowProcessor headerRowProcessor = new HeaderRowProcessor();
CPS settings = parserSettings.get();
settings.setRowProcessor(headerRowProcessor);
return unmarshaller.unmarshal(reader, createParser(settings), headerRowProcessor);
} finally {
reader.close();
}
} }


/** /**
Expand Down
Expand Up @@ -19,7 +19,7 @@
import java.io.Writer; import java.io.Writer;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;


import com.univocity.parsers.fixed.FixedWidthFieldLengths; import com.univocity.parsers.fixed.FixedWidthFields;
import com.univocity.parsers.fixed.FixedWidthFormat; import com.univocity.parsers.fixed.FixedWidthFormat;
import com.univocity.parsers.fixed.FixedWidthParser; import com.univocity.parsers.fixed.FixedWidthParser;
import com.univocity.parsers.fixed.FixedWidthParserSettings; import com.univocity.parsers.fixed.FixedWidthParserSettings;
Expand Down Expand Up @@ -188,15 +188,15 @@ protected void configureFormat(FixedWidthFormat format) {
* *
* @return new {@code FixedWidthFieldLengths} based on the header and field lengthsl * @return new {@code FixedWidthFieldLengths} based on the header and field lengthsl
*/ */
private FixedWidthFieldLengths createFixedWidthFieldLengths() { private FixedWidthFields createFixedWidthFieldLengths() {
// Ensure that the field lengths have been defined. // Ensure that the field lengths have been defined.
if (fieldLengths == null) { if (fieldLengths == null) {
throw new IllegalArgumentException("The fieldLengths must have been defined in order to use the fixed-width format."); throw new IllegalArgumentException("The fieldLengths must have been defined in order to use the fixed-width format.");
} }


// If there's no header then we only use their length // If there's no header then we only use their length
if (headers == null) { if (headers == null) {
return new FixedWidthFieldLengths(fieldLengths); return new FixedWidthFields(fieldLengths);
} }


// Use both headers and field lengths (same size and no duplicate headers) // Use both headers and field lengths (same size and no duplicate headers)
Expand All @@ -210,7 +210,7 @@ private FixedWidthFieldLengths createFixedWidthFieldLengths() {
if (fields.size() != headers.length) { if (fields.size() != headers.length) {
throw new IllegalArgumentException("The headers cannot have duplicates in order to use the fixed-width format."); throw new IllegalArgumentException("The headers cannot have duplicates in order to use the fixed-width format.");
} }
return new FixedWidthFieldLengths(fields); return new FixedWidthFields(fields);
} }


@Override @Override
Expand Down

0 comments on commit cab92ad

Please sign in to comment.