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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new 138a0b5f CSVPrinter now uses an internal lock instead of synchronized 
methods
138a0b5f is described below

commit 138a0b5fc57f53004b48532bed3086408bd02932
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Wed May 7 07:34:35 2025 -0400

    CSVPrinter now uses an internal lock instead of synchronized methods
---
 .../java/org/apache/commons/csv/CSVPrinter.java    | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java 
b/src/main/java/org/apache/commons/csv/CSVPrinter.java
index dd1df081..e7f6dab5 100644
--- a/src/main/java/org/apache/commons/csv/CSVPrinter.java
+++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java
@@ -204,13 +204,25 @@ public final class CSVPrinter implements Flushable, 
Closeable {
     public void print(final Object value) throws IOException {
         lock.lock();
         try {
-            format.print(value, appendable, newRecord);
-            newRecord = false;
+            printRaw(value);
         } finally {
             lock.unlock();
         }
     }
 
+    /**
+     * Prints the string as the next value on the line. The value will be 
escaped or encapsulated as needed.
+     *
+     * @param value
+     *            value to be output.
+     * @throws IOException
+     *             If an I/O error occurs
+     */
+    private void printRaw(final Object value) throws IOException {
+        format.print(value, appendable, newRecord);
+        newRecord = false;
+    }
+
     /**
      * Prints a comment on a new line among the delimiter-separated values.
      *
@@ -352,17 +364,17 @@ public final class CSVPrinter implements Flushable, 
Closeable {
      * separator to the output after printing the record, so there is no need 
to call {@link #println()}.
      * </p>
      *
-     * @param values
+     * @param stream
      *            values to output.
      * @throws IOException
      *             If an I/O error occurs
      * @since 1.10.0
      */
     @SuppressWarnings("resource") // caller closes.
-    public void printRecord(final Stream<?> values) throws IOException {
+    public void printRecord(final Stream<?> stream) throws IOException {
         lock.lock();
         try {
-            IOStream.adapt(values).forEachOrdered(this::print);
+            IOStream.adapt(stream).forEachOrdered(stream.isParallel() ? 
this::printRaw : this::print);
             endOfRecord();
         } finally {
             lock.unlock();

Reply via email to