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 347c8723 Port some code from IO to NIO APIs
347c8723 is described below
commit 347c8723c0d8fb655cd867443ec83566f4ceeb8d
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jan 27 16:15:11 2023 -0500
Port some code from IO to NIO APIs
---
.../java/org/apache/commons/csv/CSVPrinterTest.java | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index 53af94da..33179246 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -41,6 +41,8 @@ import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -92,6 +94,14 @@ public class CSVPrinterTest {
private final String recordSeparator =
CSVFormat.DEFAULT.getRecordSeparator();
+ private File createTempFile() throws IOException {
+ return createTempPath().toFile();
+ }
+
+ private Path createTempPath() throws IOException {
+ return Files.createTempFile(getClass().getName(), ".csv");
+ }
+
private void doOneRandom(final CSVFormat format) throws Exception {
final Random r = new Random();
@@ -1543,7 +1553,7 @@ public class CSVPrinterTest {
@Test
public void testPrintToFileWithCharsetUtf16Be() throws IOException {
- final File file = File.createTempFile(getClass().getName(), ".csv");
+ final File file = createTempFile();
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file,
StandardCharsets.UTF_16BE)) {
printer.printRecord("a", "b\\c");
}
@@ -1552,7 +1562,7 @@ public class CSVPrinterTest {
@Test
public void testPrintToFileWithDefaultCharset() throws IOException {
- final File file = File.createTempFile(getClass().getName(), ".csv");
+ final File file = createTempFile();
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file,
Charset.defaultCharset())) {
printer.printRecord("a", "b\\c");
}
@@ -1561,11 +1571,11 @@ public class CSVPrinterTest {
@Test
public void testPrintToPathWithDefaultCharset() throws IOException {
- final File file = File.createTempFile(getClass().getName(), ".csv");
- try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(),
Charset.defaultCharset())) {
+ final Path file = createTempPath();
+ try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file,
Charset.defaultCharset())) {
printer.printRecord("a", "b\\c");
}
- assertEquals("a,b\\c" + recordSeparator,
FileUtils.readFileToString(file, Charset.defaultCharset()));
+ assertEquals("a,b\\c" + recordSeparator, new
String(Files.readAllBytes(file), Charset.defaultCharset()));
}
@Test