Skip to content

Commit e5bbf94

Browse files
committed
[CSV-295] Support for parallelism in CSVPrinter.
1 parent 0c0676d commit e5bbf94

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<!-- ADD -->
4848
<action issue="CSV-291" type="add" dev="ggregory" due-to="Gary Gregory">Make CSVRecord#values() public.</action>
4949
<action issue="CSV-264" type="add" dev="ggregory" due-to="Sagar Tiwari, Seth Falco, Alex Herbert, Gary Gregory">Add DuplicateHeaderMode for flexibility with header strictness. #114.</action>
50+
<action issue="CSV-295" type="add" dev="ggregory" due-to="Gary Gregory">Support for parallelism in CSVPrinter.</action>
5051
<!-- UPDATE -->
5152
<action type="update" dev="ggregory" due-to="Dependabot">Bump checkstyle from 8.44 to 9.2.1 #180, #190, #194, #202, #207.</action>
5253
<action type="update" dev="ggregory" due-to="Dependabot">Bump junit-jupiter from 5.8.0-M1 to 5.8.2 #179, #186, #201.</action>

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ public CSVPrinter print(final File out, final Charset charset) throws IOExceptio
17931793
* @throws IOException If an I/O error occurs.
17941794
* @since 1.4
17951795
*/
1796-
public void print(final Object value, final Appendable out, final boolean newRecord) throws IOException {
1796+
public synchronized void print(final Object value, final Appendable out, final boolean newRecord) throws IOException {
17971797
// null values are considered empty
17981798
// Only call CharSequence.toString() if you have to, helps GC-free use cases.
17991799
CharSequence charSequence;
@@ -1818,7 +1818,7 @@ public void print(final Object value, final Appendable out, final boolean newRec
18181818
print(value, charSequence, out, newRecord);
18191819
}
18201820

1821-
private void print(final Object object, final CharSequence value, final Appendable out, final boolean newRecord) throws IOException {
1821+
private synchronized void print(final Object object, final CharSequence value, final Appendable out, final boolean newRecord) throws IOException {
18221822
final int offset = 0;
18231823
final int len = value.length();
18241824
if (!newRecord) {
@@ -1893,7 +1893,7 @@ public CSVPrinter printer() throws IOException {
18931893
* @throws IOException If an I/O error occurs.
18941894
* @since 1.4
18951895
*/
1896-
public void println(final Appendable appendable) throws IOException {
1896+
public synchronized void println(final Appendable appendable) throws IOException {
18971897
if (getTrailingDelimiter()) {
18981898
append(getDelimiterString(), appendable);
18991899
}
@@ -1915,7 +1915,7 @@ public void println(final Appendable appendable) throws IOException {
19151915
* @throws IOException If an I/O error occurs.
19161916
* @since 1.4
19171917
*/
1918-
public void printRecord(final Appendable appendable, final Object... values) throws IOException {
1918+
public synchronized void printRecord(final Appendable appendable, final Object... values) throws IOException {
19191919
for (int i = 0; i < values.length; i++) {
19201920
print(values[i], appendable, i == 0);
19211921
}

src/main/java/org/apache/commons/csv/CSVPrinter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Appendable getOut() {
162162
* @throws IOException
163163
* If an I/O error occurs
164164
*/
165-
public void print(final Object value) throws IOException {
165+
public synchronized void print(final Object value) throws IOException {
166166
format.print(value, appendable, newRecord);
167167
newRecord = false;
168168
}
@@ -188,7 +188,7 @@ public void print(final Object value) throws IOException {
188188
* @throws IOException
189189
* If an I/O error occurs
190190
*/
191-
public void printComment(final String comment) throws IOException {
191+
public synchronized void printComment(final String comment) throws IOException {
192192
if (comment == null || !format.isCommentMarkerSet()) {
193193
return;
194194
}
@@ -226,7 +226,7 @@ public void printComment(final String comment) throws IOException {
226226
* @throws SQLException If a database access error occurs or this method is called on a closed result set.
227227
* @since 1.9.0
228228
*/
229-
public void printHeaders(final ResultSet resultSet) throws IOException, SQLException {
229+
public synchronized void printHeaders(final ResultSet resultSet) throws IOException, SQLException {
230230
printRecord((Object[]) format.builder().setHeader(resultSet).build().getHeader());
231231
}
232232

@@ -236,7 +236,7 @@ public void printHeaders(final ResultSet resultSet) throws IOException, SQLExcep
236236
* @throws IOException
237237
* If an I/O error occurs
238238
*/
239-
public void println() throws IOException {
239+
public synchronized void println() throws IOException {
240240
format.println(appendable);
241241
newRecord = true;
242242
}
@@ -254,7 +254,7 @@ public void println() throws IOException {
254254
* @throws IOException
255255
* If an I/O error occurs
256256
*/
257-
public void printRecord(final Iterable<?> values) throws IOException {
257+
public synchronized void printRecord(final Iterable<?> values) throws IOException {
258258
for (final Object value : values) {
259259
print(value);
260260
}

0 commit comments

Comments
 (0)