This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new f3507f4d740 Use the newly maintained univocity parsers (#15610)
f3507f4d740 is described below

commit f3507f4d74047aa133369a3ed82832dde6dd2e1e
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Sep 18 20:17:42 2024 +0200

    Use the newly maintained univocity parsers (#15610)
    
    * remove locking for lazy initialized fields, as those are not very 
expensive to create, so worst case, we have double initiatization, which is not 
a problem
    * move the TLS into the HeaderRowProcessor
    * remove 'or not' in 'whether or not'
---
 components/camel-univocity-parsers/pom.xml         |   4 +-
 .../org/apache/camel/dataformat.properties         |   2 +-
 .../univocity/AbstractUniVocityDataFormat.java     | 104 ++++++++-------------
 .../dataformat/univocity/HeaderRowProcessor.java   |  12 +--
 .../univocity/UniVocityCsvDataFormat.java          |   1 -
 .../univocity/UniVocityFixedDataFormat.java        |   1 -
 .../univocity/UniVocityTsvDataFormat.java          |   1 -
 parent/pom.xml                                     |   2 +-
 8 files changed, 51 insertions(+), 76 deletions(-)

diff --git a/components/camel-univocity-parsers/pom.xml 
b/components/camel-univocity-parsers/pom.xml
index 025a5fb4d42..722edf1a1ba 100644
--- a/components/camel-univocity-parsers/pom.xml
+++ b/components/camel-univocity-parsers/pom.xml
@@ -28,7 +28,7 @@
 
     <artifactId>camel-univocity-parsers</artifactId>
     <packaging>jar</packaging>
-    <name>Camel :: UniVocity Parsers (deprecated)</name>
+    <name>Camel :: UniVocity Parsers</name>
     <description>Camel UniVocity parsers data format support</description>
 
     <properties>
@@ -40,7 +40,7 @@
             <artifactId>camel-support</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.univocity</groupId>
+            <groupId>com.sonofab1rd</groupId>
             <artifactId>univocity-parsers</artifactId>
             <version>${univocity-parsers-version}</version>
             <type>jar</type>
diff --git 
a/components/camel-univocity-parsers/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
 
b/components/camel-univocity-parsers/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
index fd6a5828648..21818d0d532 100644
--- 
a/components/camel-univocity-parsers/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
+++ 
b/components/camel-univocity-parsers/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
@@ -3,5 +3,5 @@ dataFormats=univocityCsv univocityFixed univocityTsv
 groupId=org.apache.camel
 artifactId=camel-univocity-parsers
 version=4.9.0-SNAPSHOT
-projectName=Camel :: UniVocity Parsers (deprecated)
+projectName=Camel :: UniVocity Parsers
 projectDescription=Camel UniVocity parsers data format support
diff --git 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/AbstractUniVocityDataFormat.java
 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/AbstractUniVocityDataFormat.java
index 7c754befcbd..fbc9328d35e 100644
--- 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/AbstractUniVocityDataFormat.java
+++ 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/AbstractUniVocityDataFormat.java
@@ -47,7 +47,6 @@ import static 
org.apache.camel.support.ExchangeHelper.getCharsetName;
  * @param <P>   uniVocity parser class
  * @param <DF>  the data format class (for providing a fluent API)
  */
-@Deprecated(since = "4.8.0")
 public abstract class AbstractUniVocityDataFormat<
         F extends Format, CWS extends CommonWriterSettings<F>,
         W extends AbstractWriter<CWS>, CPS extends CommonParserSettings<F>, P 
extends AbstractParser<CPS>,
@@ -70,14 +69,11 @@ public abstract class AbstractUniVocityDataFormat<
     protected boolean asMap;
 
     private volatile CWS writerSettings;
-    private final Object writerSettingsToken = new Object();
     private volatile Marshaller<W> marshaller;
 
-    // We're using a ThreadLocal for the parser settings because in order to 
retrieve the headers we need to change the
-    // settings each time we're parsing
-    private volatile ThreadLocal<CPS> parserSettings;
-    private final Object parserSettingsToken = new Object();
+    private volatile CPS parserSettings;
     private volatile Unmarshaller<P> unmarshaller;
+    private final HeaderRowProcessor headerRowProcessor = new 
HeaderRowProcessor();
 
     /**
      * {@inheritDoc}
@@ -85,19 +81,14 @@ public abstract class AbstractUniVocityDataFormat<
     @Override
     public void marshal(Exchange exchange, Object body, OutputStream stream) 
throws Exception {
         if (writerSettings == null) {
-            synchronized (writerSettingsToken) {
-                if (writerSettings == null) {
-                    marshaller = new Marshaller<>(headers, headers == null);
-                    writerSettings = createAndConfigureWriterSettings();
-                }
-            }
+            writerSettings = createAndConfigureWriterSettings();
+        }
+        if (marshaller == null) {
+            marshaller = new Marshaller<>(headers, headers == null);
         }
 
-        Writer writer = new OutputStreamWriter(stream, 
getCharsetName(exchange));
-        try {
+        try (Writer writer = new OutputStreamWriter(stream, 
getCharsetName(exchange))) {
             marshaller.marshal(exchange, body, createWriter(writer, 
writerSettings));
-        } finally {
-            writer.close();
         }
     }
 
@@ -107,23 +98,13 @@ public abstract class AbstractUniVocityDataFormat<
     @Override
     public Object unmarshal(Exchange exchange, InputStream stream) throws 
Exception {
         if (parserSettings == null) {
-            synchronized (parserSettingsToken) {
-                if (parserSettings == null) {
-                    unmarshaller = new Unmarshaller<>(lazyLoad, asMap);
-                    parserSettings = new ThreadLocal<CPS>() {
-                        @Override
-                        protected CPS initialValue() {
-                            return createAndConfigureParserSettings();
-                        }
-                    };
-                }
-            }
+            parserSettings = createAndConfigureParserSettings();
+        }
+        if (unmarshaller == null) {
+            unmarshaller = new Unmarshaller<>(lazyLoad, asMap);
         }
 
-        HeaderRowProcessor headerRowProcessor = new HeaderRowProcessor();
-        CPS settings = parserSettings.get();
-        settings.setProcessor(headerRowProcessor);
-        P parser = createParser(settings);
+        P parser = createParser(parserSettings);
         // univocity-parsers is responsible for closing the reader, even in 
case of error
         Reader reader = new InputStreamReader(stream, 
getCharsetName(exchange));
         return unmarshaller.unmarshal(reader, parser, headerRowProcessor);
@@ -152,9 +133,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not empty lines should be ignored. If {@code null} then 
the default settings value is used.
+     * Gets whether empty lines should be ignored. If {@code null} then the 
default settings value is used.
      *
-     * @return whether or not empty lines should be ignored
+     * @return whether empty lines should be ignored
      * @see    com.univocity.parsers.common.CommonSettings#getSkipEmptyLines()
      */
     public Boolean getSkipEmptyLines() {
@@ -162,9 +143,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Sets whether or not empty lines should be ignored. If {@code null} then 
the default settings value is used.
+     * Sets whether empty lines should be ignored. If {@code null} then the 
default settings value is used.
      *
-     * @param  skipEmptyLines whether or not empty lines should be ignored
+     * @param  skipEmptyLines whether empty lines should be ignored
      * @return                current data format instance, fluent API
      * @see                   
com.univocity.parsers.common.CommonSettings#setSkipEmptyLines(boolean)
      */
@@ -174,10 +155,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not trailing whitespaces should be ignored. If {@code 
null} then the default settings value is
-     * used.
+     * Gets whether trailing whitespaces should be ignored. If {@code null} 
then the default settings value is used.
      *
-     * @return whether or not trailing whitespaces should be ignored
+     * @return whethertrailing whitespaces should be ignored
      * @see    
com.univocity.parsers.common.CommonSettings#getIgnoreTrailingWhitespaces()
      */
     public Boolean getIgnoreTrailingWhitespaces() {
@@ -185,10 +165,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Sets whether or not trailing whitespaces should be ignored. If {@code 
null} then the default settings value is
-     * used.
+     * Sets whether trailing whitespaces should be ignored. If {@code null} 
then the default settings value is used.
      *
-     * @param  ignoreTrailingWhitespaces whether or not trailing whitespaces 
should be ignored
+     * @param  ignoreTrailingWhitespaces whether trailing whitespaces should 
be ignored
      * @return                           current data format instance, fluent 
API
      * @see                              
com.univocity.parsers.common.CommonSettings#setIgnoreTrailingWhitespaces(boolean)
      */
@@ -198,10 +177,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not leading whitespaces should be ignored. If {@code 
null} then the default settings value is
-     * used.
+     * Gets whetherleading whitespaces should be ignored. If {@code null} then 
the default settings value is used.
      *
-     * @return whether or not leading whitespaces should be ignored
+     * @return whetherleading whitespaces should be ignored
      * @see    
com.univocity.parsers.common.CommonSettings#getIgnoreLeadingWhitespaces()
      */
     public Boolean getIgnoreLeadingWhitespaces() {
@@ -209,10 +187,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Sets whether or not leading whitespaces should be ignored. If {@code 
null} then the default settings value is
-     * used.
+     * Sets whetherleading whitespaces should be ignored. If {@code null} then 
the default settings value is used.
      *
-     * @param  ignoreLeadingWhitespaces whether or not leading whitespaces 
should be ignored
+     * @param  ignoreLeadingWhitespaces whetherleading whitespaces should be 
ignored
      * @return                          current data format instance, fluent 
API
      * @see                             
com.univocity.parsers.common.CommonSettings#setIgnoreLeadingWhitespaces(boolean)
      */
@@ -222,10 +199,10 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not headers are disabled. If {@code true} then it 
passes {@code null} to
+     * Gets whetherheaders are disabled. If {@code true} then it passes {@code 
null} to
      * {@link 
com.univocity.parsers.common.CommonSettings#setHeaders(String...)} in order to 
disabled them.
      *
-     * @return whether or not headers are disabled
+     * @return whetherheaders are disabled
      * @see    com.univocity.parsers.common.CommonSettings#getHeaders()
      */
     public boolean isHeadersDisabled() {
@@ -233,10 +210,10 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Sets whether or not headers are disabled. If {@code true} then it 
passes {@code null} to
+     * Sets whetherheaders are disabled. If {@code true} then it passes {@code 
null} to
      * {@link 
com.univocity.parsers.common.CommonSettings#setHeaders(String...)} in order to 
disabled them.
      *
-     * @param  headersDisabled whether or not headers are disabled
+     * @param  headersDisabled whetherheaders are disabled
      * @return                 current data format instance, fluent API
      * @see                    
com.univocity.parsers.common.CommonSettings#setHeaders(String...)
      */
@@ -268,9 +245,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not the header extraction is enabled. If {@code null} 
then the default settings value is used.
+     * Gets whetherthe header extraction is enabled. If {@code null} then the 
default settings value is used.
      *
-     * @return whether or not the header extraction is enabled
+     * @return whetherthe header extraction is enabled
      * @see    
com.univocity.parsers.common.CommonParserSettings#isHeaderExtractionEnabled()
      */
     public Boolean getHeaderExtractionEnabled() {
@@ -278,9 +255,9 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Sets whether or not the header extraction is enabled. If {@code null} 
then the default settings value is used.
+     * Sets whetherthe header extraction is enabled. If {@code null} then the 
default settings value is used.
      *
-     * @param  headerExtractionEnabled whether or not the header extraction is 
enabled
+     * @param  headerExtractionEnabled whetherthe header extraction is enabled
      * @return                         current data format instance, fluent API
      * @see                            
com.univocity.parsers.common.CommonParserSettings#setHeaderExtractionEnabled(boolean)
      */
@@ -400,18 +377,18 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not the unmarshalling should read lines lazily.
+     * Gets whetherthe unmarshalling should read lines lazily.
      *
-     * @return whether or not the unmarshalling should read lines lazily
+     * @return whetherthe unmarshalling should read lines lazily
      */
     public boolean isLazyLoad() {
         return lazyLoad;
     }
 
     /**
-     * Sets whether or not the unmarshalling should read lines lazily.
+     * Sets whetherthe unmarshalling should read lines lazily.
      *
-     * @param  lazyLoad whether or not the unmarshalling should read lines 
lazily
+     * @param  lazyLoad whetherthe unmarshalling should read lines lazily
      * @return          current data format instance, fluent API
      */
     public DF setLazyLoad(boolean lazyLoad) {
@@ -420,18 +397,18 @@ public abstract class AbstractUniVocityDataFormat<
     }
 
     /**
-     * Gets whether or not the unmarshalling should produces maps instead of 
lists.
+     * Gets whetherthe unmarshalling should produces maps instead of lists.
      *
-     * @return whether or not the unmarshalling should produces maps instead 
of lists
+     * @return whetherthe unmarshalling should produces maps instead of lists
      */
     public boolean isAsMap() {
         return asMap;
     }
 
     /**
-     * Sets whether or not the unmarshalling should produces maps instead of 
lists.
+     * Sets whetherthe unmarshalling should produces maps instead of lists.
      *
-     * @param  asMap whether or not the unmarshalling should produces maps 
instead of lists
+     * @param  asMap whetherthe unmarshalling should produces maps instead of 
lists
      * @return       current data format instance, fluent API
      */
     public DF setAsMap(boolean asMap) {
@@ -537,6 +514,7 @@ public abstract class AbstractUniVocityDataFormat<
         CPS settings = createParserSettings();
         configureParserSettings(settings);
         configureFormat(settings.getFormat());
+        settings.setProcessor(headerRowProcessor);
         return settings;
     }
 
diff --git 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/HeaderRowProcessor.java
 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/HeaderRowProcessor.java
index efc72f2b751..2b4ee4b06db 100644
--- 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/HeaderRowProcessor.java
+++ 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/HeaderRowProcessor.java
@@ -23,7 +23,7 @@ import com.univocity.parsers.common.processor.RowProcessor;
  * This class is used by the unmarshaller in order to retrieve the headers.
  */
 final class HeaderRowProcessor implements RowProcessor {
-    private String[] headers;
+    private final static ThreadLocal<String[]> headers = new ThreadLocal<>();
 
     /**
      * Called when the processing starts, it clears the headers
@@ -32,7 +32,7 @@ final class HeaderRowProcessor implements RowProcessor {
      */
     @Override
     public void processStarted(ParsingContext context) {
-        headers = null;
+        headers.set(null);
     }
 
     /**
@@ -43,8 +43,8 @@ final class HeaderRowProcessor implements RowProcessor {
      */
     @Override
     public void rowProcessed(String[] row, ParsingContext context) {
-        if (headers == null) {
-            headers = context.headers();
+        if (headers.get() == null) {
+            headers.set(context.headers());
         }
     }
 
@@ -55,7 +55,7 @@ final class HeaderRowProcessor implements RowProcessor {
      */
     @Override
     public void processEnded(ParsingContext context) {
-        headers = null;
+        headers.set(null);
     }
 
     /**
@@ -64,6 +64,6 @@ final class HeaderRowProcessor implements RowProcessor {
      * @return the headers
      */
     public String[] getHeaders() {
-        return headers;
+        return headers.get();
     }
 }
diff --git 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormat.java
 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormat.java
index 1cc4610b3c9..ceaf2615b7e 100644
--- 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormat.java
+++ 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormat.java
@@ -29,7 +29,6 @@ import org.apache.camel.spi.annotations.Dataformat;
  * This class is the data format that uses the CSV uniVocity parser.
  */
 @Dataformat("univocityCsv")
-@Deprecated(since = "4.8.0")
 public class UniVocityCsvDataFormat
         extends
         AbstractUniVocityDataFormat<CsvFormat, CsvWriterSettings, CsvWriter, 
CsvParserSettings, CsvParser, UniVocityCsvDataFormat> {
diff --git 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityFixedDataFormat.java
 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityFixedDataFormat.java
index eeb99a237df..09dd52c3390 100644
--- 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityFixedDataFormat.java
+++ 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityFixedDataFormat.java
@@ -31,7 +31,6 @@ import org.apache.camel.spi.annotations.Dataformat;
  * This class is the data format that uses the fixed-width uniVocity parser.
  */
 @Dataformat("univocityFixed")
-@Deprecated(since = "4.8.0")
 public class UniVocityFixedDataFormat
         extends
         AbstractUniVocityDataFormat<FixedWidthFormat, 
FixedWidthWriterSettings, FixedWidthWriter, FixedWidthParserSettings, 
FixedWidthParser, UniVocityFixedDataFormat> {
diff --git 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityTsvDataFormat.java
 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityTsvDataFormat.java
index 5fa7a5037f5..204b1c3e4eb 100644
--- 
a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityTsvDataFormat.java
+++ 
b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/UniVocityTsvDataFormat.java
@@ -29,7 +29,6 @@ import org.apache.camel.spi.annotations.Dataformat;
  * This class is the data format that uses the TSV uniVocity parser.
  */
 @Dataformat("univocityTsv")
-@Deprecated(since = "4.8.0")
 public class UniVocityTsvDataFormat
         extends
         AbstractUniVocityDataFormat<TsvFormat, TsvWriterSettings, TsvWriter, 
TsvParserSettings, TsvParser, UniVocityTsvDataFormat> {
diff --git a/parent/pom.xml b/parent/pom.xml
index 828badeee3c..ad90a6075f9 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -475,7 +475,7 @@
         <twilio-version>10.5.0</twilio-version>
         <twitter4j-version>4.1.2</twitter4j-version>
         <undertow-version>2.3.17.Final</undertow-version>
-        <univocity-parsers-version>2.9.1</univocity-parsers-version>
+        <univocity-parsers-version>2.10.0</univocity-parsers-version>
         <validation-api-version>2.0.1.Final</validation-api-version>
         <vavr-version>0.10.4</vavr-version>
         <velocity-tools-version>3.1</velocity-tools-version>

Reply via email to