Author: ggregory
Date: Tue Jun 14 06:00:15 2016
New Revision: 1748349
URL: http://svn.apache.org/viewvc?rev=1748349&view=rev
Log:
Add convenience API CSVFormat.print(Path, Charset) (JIRA is down ATM).
Modified:
commons/proper/csv/trunk/src/changes/changes.xml
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Modified: commons/proper/csv/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/changes/changes.xml?rev=1748349&r1=1748348&r2=1748349&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/changes/changes.xml (original)
+++ commons/proper/csv/trunk/src/changes/changes.xml Tue Jun 14 06:00:15 2016
@@ -41,6 +41,7 @@
<release version="1.5" date="2016-MM-DD" description="Bug fix release">
<action issue="CSV-187" type="update" dev="ggregory" due-to="Gary
Gregory">Update platform requirement from Java 6 to 7.</action>
<action issue="CSV-???" type="add" dev="ggregory" due-to="Gary
Gregory">Add convenience API CSVFormat.print(File, Charset)</action>
+ <action issue="CSV-???" type="add" dev="ggregory" due-to="Gary
Gregory">Add convenience API CSVFormat.print(Path, Charset)</action>
</release>
<release version="1.4" date="2016-05-28" description="Feature and bug fix
release">
<action issue="CSV-181" type="update" dev="ggregory" due-to="Gary
Gregory">Make CSVPrinter.print(Object) GC-free.</action>
Modified:
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL:
http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1748349&r1=1748348&r2=1748349&view=diff
==============================================================================
---
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
(original)
+++
commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
Tue Jun 14 06:00:15 2016
@@ -36,6 +36,7 @@ import java.io.Reader;
import java.io.Serializable;
import java.io.StringWriter;
import java.nio.charset.Charset;
+import java.nio.file.Path;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
@@ -889,6 +890,26 @@ public final class CSVFormat implements
}
/**
+ * Prints to the specified output.
+ *
+ * <p>
+ * See also {@link CSVPrinter}.
+ * </p>
+ *
+ * @param out
+ * the output
+ * @param charset
+ * A charset
+ * @return a printer to an output
+ * @throws IOException
+ * thrown if the optional header cannot be printed.
+ * @since 1.5
+ */
+ public CSVPrinter print(final Path out, Charset charset) throws
IOException {
+ return print(out.toFile(), charset);
+ }
+
+ /**
* Prints the {@code value} as the next value on the line to {@code out}.
The value will be escaped or encapsulated
* as needed. Useful when one wants to avoid creating CSVPrinters.
*
Modified:
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java?rev=1748349&r1=1748348&r2=1748349&view=diff
==============================================================================
---
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
(original)
+++
commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Tue Jun 14 06:00:15 2016
@@ -28,6 +28,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -738,6 +739,15 @@ public class CSVPrinterTest {
printer.printRecord("a", "b\\c");
}
assertEquals("a,b\\c" + recordSeparator,
FileUtils.readFileToString(file, Charset.defaultCharset()));
+ }
+
+ @Test
+ public void testPrintToPathWithDefaultCharset() throws IOException {
+ File file = File.createTempFile(getClass().getName(), ".csv");
+ try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(),
Charset.defaultCharset())) {
+ printer.printRecord("a", "b\\c");
+ }
+ assertEquals("a,b\\c" + recordSeparator,
FileUtils.readFileToString(file, Charset.defaultCharset()));
}
@Test