|
40 | 40 |
|
41 | 41 | import org.apache.commons.io.function.IOStream; |
42 | 42 |
|
| 43 | +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 44 | + |
43 | 45 | /** |
44 | 46 | * Prints values in a {@link CSVFormat CSV format}. |
45 | 47 | * |
@@ -151,14 +153,10 @@ public void close(final boolean flush) throws IOException { |
151 | 153 | * @throws IOException |
152 | 154 | * If an I/O error occurs |
153 | 155 | */ |
| 156 | + @SuppressFBWarnings(value = "AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE", justification = "https://github.com/spotbugs/spotbugs/issues/3428") |
154 | 157 | private void endOfRecord() throws IOException { |
155 | | - lock.lock(); |
156 | | - try { |
157 | | - println(); |
158 | | - recordCount++; |
159 | | - } finally { |
160 | | - lock.unlock(); |
161 | | - } |
| 158 | + println(); |
| 159 | + recordCount++; |
162 | 160 | } |
163 | 161 |
|
164 | 162 | /** |
@@ -494,21 +492,26 @@ public void printRecords(final Object... values) throws IOException { |
494 | 492 | public void printRecords(final ResultSet resultSet) throws SQLException, IOException { |
495 | 493 | final int columnCount = resultSet.getMetaData().getColumnCount(); |
496 | 494 | while (resultSet.next() && format.useRow(resultSet.getRow())) { |
497 | | - for (int i = 1; i <= columnCount; i++) { |
498 | | - final Object object = resultSet.getObject(i); |
499 | | - if (object instanceof Clob) { |
500 | | - try (Reader reader = ((Clob) object).getCharacterStream()) { |
501 | | - print(reader); |
| 495 | + lock.lock(); |
| 496 | + try { |
| 497 | + for (int i = 1; i <= columnCount; i++) { |
| 498 | + final Object object = resultSet.getObject(i); |
| 499 | + if (object instanceof Clob) { |
| 500 | + try (Reader reader = ((Clob) object).getCharacterStream()) { |
| 501 | + print(reader); |
| 502 | + } |
| 503 | + } else if (object instanceof Blob) { |
| 504 | + try (InputStream inputStream = ((Blob) object).getBinaryStream()) { |
| 505 | + print(inputStream); |
| 506 | + } |
| 507 | + } else { |
| 508 | + print(object); |
502 | 509 | } |
503 | | - } else if (object instanceof Blob) { |
504 | | - try (InputStream inputStream = ((Blob) object).getBinaryStream()) { |
505 | | - print(inputStream); |
506 | | - } |
507 | | - } else { |
508 | | - print(object); |
509 | 510 | } |
| 511 | + endOfRecord(); |
| 512 | + } finally { |
| 513 | + lock.unlock(); |
510 | 514 | } |
511 | | - endOfRecord(); |
512 | 515 | } |
513 | 516 | } |
514 | 517 |
|
|
0 commit comments