Author: davsclaus
Date: Mon Jun 4 17:59:17 2012
New Revision: 1346061
URL: http://svn.apache.org/viewvc?rev=1346061&view=rev
Log:
CAMEL-5035: Added support for handling long/short lines to flatpack component.
Thanks to Chris Geer for the patch.
Added:
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedMixed/
- copied from r1346059,
camel/trunk/components/camel-flatpack/src/test/data/fixedMixed/
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedShort/
- copied from r1346059,
camel/trunk/components/camel-flatpack/src/test/data/fixedShort/
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthAllowLongTest.java
- copied unchanged from r1346059,
camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthAllowLongTest.java
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest.java
- copied unchanged from r1346059,
camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest.java
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthAllowShortTest.java
- copied unchanged from r1346059,
camel/trunk/components/camel-flatpack/src/test/java/org/apache/camel/component/flatpack/FixedLengthAllowShortTest.java
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowLongTest-context.xml
- copied unchanged from r1346059,
camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowLongTest-context.xml
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest-context.xml
- copied unchanged from r1346059,
camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest-context.xml
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortTest-context.xml
- copied unchanged from r1346059,
camel/trunk/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortTest-context.xml
Modified:
camel/branches/camel-2.9.x/ (props changed)
camel/branches/camel-2.9.x/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FixedLengthEndpoint.java
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedLong/PEOPLE-FixedLength.txt
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1346059
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-2.9.x/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FixedLengthEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FixedLengthEndpoint.java?rev=1346061&r1=1346060&r2=1346061&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FixedLengthEndpoint.java
(original)
+++
camel/branches/camel-2.9.x/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FixedLengthEndpoint.java
Mon Jun 4 17:59:17 2012
@@ -50,6 +50,8 @@ public class FixedLengthEndpoint extends
private LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
private ParserFactory parserFactory = DefaultParserFactory.getInstance();
private boolean splitRows = true;
+ private boolean allowShortLines;
+ private boolean ignoreExtraColumns;
public FixedLengthEndpoint() {
}
@@ -87,7 +89,16 @@ public class FixedLengthEndpoint extends
protected Parser createParser(String resourceUri, Reader bodyReader)
throws IOException {
InputStream is =
ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(),
resourceUri);
InputStreamReader reader = new InputStreamReader(is);
- return getParserFactory().newFixedLengthParser(reader, bodyReader);
+ Parser parser = getParserFactory().newFixedLengthParser(reader,
bodyReader);
+ if (allowShortLines) {
+ parser.setHandlingShortLines(true);
+ parser.setIgnoreParseWarnings(true);
+ }
+ if (ignoreExtraColumns) {
+ parser.setIgnoreExtraColumns(true);
+ parser.setIgnoreParseWarnings(true);
+ }
+ return parser;
}
// Properties
@@ -117,7 +128,32 @@ public class FixedLengthEndpoint extends
return splitRows;
}
+ /**
+ * Sets the Component to send each row as a separate exchange once parsed
+ */
public void setSplitRows(boolean splitRows) {
this.splitRows = splitRows;
}
+
+ public boolean isAllowShortLines() {
+ return this.allowShortLines;
+ }
+
+ /**
+ * Allows for lines to be shorter than expected and ignores the extra
characters
+ */
+ public void setAllowShortLines(boolean allowShortLines) {
+ this.allowShortLines = allowShortLines;
+ }
+
+ /**
+ * Allows for lines to be longer than expected and ignores the extra
characters
+ */
+ public void setIgnoreExtraColumns(boolean ignoreExtraColumns) {
+ this.ignoreExtraColumns = ignoreExtraColumns;
+ }
+
+ public boolean isIgnoreExtraColumns() {
+ return ignoreExtraColumns;
+ }
}
Modified:
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedLong/PEOPLE-FixedLength.txt
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedLong/PEOPLE-FixedLength.txt?rev=1346061&r1=1346060&r2=1346061&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedLong/PEOPLE-FixedLength.txt
(original)
+++
camel/branches/camel-2.9.x/components/camel-flatpack/src/test/data/fixedLong/PEOPLE-FixedLength.txt
Mon Jun 4 17:59:17 2012
@@ -1,4 +1,4 @@
-JOHN DOE 1234
CIRCLE CT
ELYRIA
OH44035*
-JIMMY SMITH 180 SOME
ST
AVON
OH44011*
-JANE DOE 111
MILKY WY
AMHERST
OH44001*
-FRED FLINTSTONE 123
ROCKY WY
BEDROCK
AZ12345*
+JOHN-LONG DOE 1234
CIRCLE CT
ELYRIA
OH44035*
+JIMMY-LONG SMITH 180 SOME
ST
AVON
OH44011*
+JANE-LONG DOE 111
MILKY WY
AMHERST
OH44001*
+FRED-LONG FLINTSTONE 123
ROCKY WY
BEDROCK
AZ12345*