Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9C593200AF7 for ; Tue, 14 Jun 2016 17:48:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9AF33160A56; Tue, 14 Jun 2016 15:48:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9428A160A06 for ; Tue, 14 Jun 2016 17:48:05 +0200 (CEST) Received: (qmail 68070 invoked by uid 500); 14 Jun 2016 15:48:04 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 68057 invoked by uid 99); 14 Jun 2016 15:48:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jun 2016 15:48:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 52817C028E for ; Tue, 14 Jun 2016 15:48:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.28 X-Spam-Level: * X-Spam-Status: No, score=1.28 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=carmanconsulting-com.20150623.gappssmtp.com Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id tFkTa9z3j-65 for ; Tue, 14 Jun 2016 15:47:59 +0000 (UTC) Received: from mail-vk0-f53.google.com (mail-vk0-f53.google.com [209.85.213.53]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTPS id 5B6E55FB76 for ; Tue, 14 Jun 2016 15:47:59 +0000 (UTC) Received: by mail-vk0-f53.google.com with SMTP id t129so99049677vka.1 for ; Tue, 14 Jun 2016 08:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carmanconsulting-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=C3xBOyQ8RdSDoF9fk+0nEA3WgzpMovoFKT4Lvz7HPxw=; b=2Eyfnn+titArYr178o7oaabzEVAUDMvh5MRVd160+LJWgCOk9wN+sj3m3rNQE82co9 x+dOWoCbCB+M4byKHwfvuRQmKeA/a7xMRr83QGgSmq9IiEqKvoE8Y662fMMFhbwBcaZb yLM0OHNeVkqDux2PUW4zB8OH/EJ5H8Ii791zemuQ/UM02BNnfMXtAMqChWTi7E/c5ZaV kOU0fogsafr8F2lYXMN0mIeKvnUdAZE781ljgLAYE885Bym+wLCzu9e+VxyylCXe2UkA Qoy7vU6NXm7kRq2hfPh83BhGdEnEbREHpaKblIalaOfAqzt3J0WSEz5cvwxSLoN22Zpg J24A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=C3xBOyQ8RdSDoF9fk+0nEA3WgzpMovoFKT4Lvz7HPxw=; b=CN1oDwa700N+6OH1aW+kIMhDRPGakeFG0xaGVwhHQtIxO85heZjpS4T/eOb1YlXa+J 0W6MmCWnNxPybFUk9UhUxc1NQk2dz+8lNf+H6o+hVpIUpQ9pPGzDmQMXxYbkBMFT11oZ EKdk7/PZMoqlkPurISC6EcDscehra1mVdifp8kadc83xjbL+aypiXV7fMZuq3ydJWOXt u8YyE7tMN+6QABPLMUmoy890BB3FrgX+ljwbWbgFtJrdejlxgX64ULS/8dU/I4EH3Vk5 gSn0GY3quT8/L8E7e0ugTdSkuXfI6HuBWRAswY6GPPmXtWVz0kT2YTcrVHvyOwtZ/UGS CB7g== X-Gm-Message-State: ALyK8tImN4emw1svAvqIqXTWq6Zqq/MIWmKRkdH8QKoE3k1Onm7nkCHhEC/Ezm7NKHxPatIRZOAVyt11rs7r/w== X-Received: by 10.176.68.165 with SMTP id n34mr9203475uan.51.1465919271991; Tue, 14 Jun 2016 08:47:51 -0700 (PDT) MIME-Version: 1.0 References: <20160614055333.8F68A3A0096@svn01-us-west.apache.org> In-Reply-To: From: James Carman Date: Tue, 14 Jun 2016 15:47:41 +0000 Message-ID: Subject: Re: svn commit: r1748347 - in /commons/proper/csv/trunk/src: changes/changes.xml main/java/org/apache/commons/csv/CSVFormat.java test/java/org/apache/commons/csv/CSVPrinterTest.java To: Commons Developers List Content-Type: multipart/alternative; boundary=001a114c8f967a431505353eed08 archived-at: Tue, 14 Jun 2016 15:48:06 -0000 --001a114c8f967a431505353eed08 Content-Type: text/plain; charset=UTF-8 Can folks perhaps combine commons-io to help? On Tue, Jun 14, 2016 at 11:27 AM Gary Gregory wrote: > On Jun 14, 2016 5:19 AM, "James Carman" > wrote: > > > > Are Readers that hard to create? > > No, but remembering how to do this is a pain: > > File out = ... > > Charset charset = ... > > CSVPrinter printer = new CSVPrinter(new OutputStreamWriter(new > FileOutputStream(out), charset), format); > Instead of: > > format.print(file, charset); > > We can roll these two APIs back out and document that the components only > provides low-level APIs, forget convenience APIs. > > We can also find a better home for these APIs... like where? On the printer > static side? > > Gary > > Itv > > > > On Tue, Jun 14, 2016 at 2:17 AM Gary Gregory > wrote: > > > > > On Mon, Jun 13, 2016 at 11:13 PM, Benedikt Ritter > > > wrote: > > > > > > > I don't like how we're evolving CSVFormat. It is becoming a dumping > > > ground > > > > for anything that may be useful or convenient. The more methods we > add, > > > the > > > > harder it becomes for users to find the right method for their use > case. > > > > > > > > > > Small is nice, I get that. But how would you do it differently so that > I > > > can easily use Paths, Files, URI, and URLs... > > > > > > Gary > > > > > > > > > > > > > > Benedikt > > > > > > > > schrieb am Di., 14. Juni 2016 um 07:53 Uhr: > > > > > > > > > Author: ggregory > > > > > Date: Tue Jun 14 05:53:32 2016 > > > > > New Revision: 1748347 > > > > > > > > > > URL: http://svn.apache.org/viewvc?rev=1748347&view=rev > > > > > Log: > > > > > Add convenience API CSVFormat.print(File, 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=1748347&r1=1748346&r2=1748347&view=diff > > > > > > > > > > > > > > > > > > > ============================================================================== > > > > > --- commons/proper/csv/trunk/src/changes/changes.xml (original) > > > > > +++ commons/proper/csv/trunk/src/changes/changes.xml Tue Jun 14 > > > 05:53:32 > > > > > 2016 > > > > > @@ -40,6 +40,7 @@ > > > > > > > > > > > > > > > > > due-to="Gary > > > > > Gregory">Update platform requirement from Java 6 to 7. > > > > > + due-to="Gary > > > > > Gregory">Add convenience API CSVFormat.print(File, > Charset) > > > > > > > > > > > > > > > > > due-to="Gary > > > > > Gregory">Make CSVPrinter.print(Object) GC-free. > > > > > > > > > > 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=1748347&r1=1748346&r2=1748347&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 05:53:32 2016 > > > > > @@ -28,10 +28,14 @@ import static org.apache.commons.csv.Con > > > > > import static org.apache.commons.csv.Constants.SP; > > > > > import static org.apache.commons.csv.Constants.TAB; > > > > > > > > > > +import java.io.File; > > > > > +import java.io.FileOutputStream; > > > > > import java.io.IOException; > > > > > +import java.io.OutputStreamWriter; > > > > > import java.io.Reader; > > > > > import java.io.Serializable; > > > > > import java.io.StringWriter; > > > > > +import java.nio.charset.Charset; > > > > > import java.sql.ResultSet; > > > > > import java.sql.ResultSetMetaData; > > > > > import java.sql.SQLException; > > > > > @@ -864,6 +868,27 @@ public final class CSVFormat implements > > > > > } > > > > > > > > > > /** > > > > > + * Prints to the specified output. > > > > > + * > > > > > + *

> > > > > + * See also {@link CSVPrinter}. > > > > > + *

> > > > > + * > > > > > + * @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 File out, Charset charset) > throws > > > > > IOException { > > > > > + // The FileWriter will be closed when close() is called. > > > > > + return new CSVPrinter(new OutputStreamWriter(new > > > > > FileOutputStream(out), charset), this); > > > > > + } > > > > > + > > > > > + /** > > > > > * 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=1748347&r1=1748346&r2=1748347&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 05:53:32 2016 > > > > > @@ -22,9 +22,12 @@ import static org.junit.Assert.assertArr > > > > > import static org.junit.Assert.assertEquals; > > > > > import static org.junit.Assert.assertFalse; > > > > > > > > > > +import java.io.File; > > > > > import java.io.IOException; > > > > > import java.io.StringReader; > > > > > import java.io.StringWriter; > > > > > +import java.nio.charset.Charset; > > > > > +import java.nio.charset.StandardCharsets; > > > > > import java.sql.Connection; > > > > > import java.sql.DriverManager; > > > > > import java.sql.ResultSet; > > > > > @@ -38,6 +41,7 @@ import java.util.List; > > > > > import java.util.Objects; > > > > > import java.util.Random; > > > > > > > > > > +import org.apache.commons.io.FileUtils; > > > > > import org.junit.Assert; > > > > > import org.junit.Ignore; > > > > > import org.junit.Test; > > > > > @@ -728,6 +732,24 @@ public class CSVPrinterTest { > > > > > } > > > > > > > > > > @Test > > > > > + public void testPrintToFileWithDefaultCharset() throws > > > IOException { > > > > > + File file = File.createTempFile(getClass().getName(), > ".csv"); > > > > > + 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())); > > > > > + } > > > > > + > > > > > + @Test > > > > > + public void testPrintToFileWithCharsetUtf16Be() throws > > > IOException { > > > > > + File file = File.createTempFile(getClass().getName(), > ".csv"); > > > > > + try (final CSVPrinter printer = > CSVFormat.DEFAULT.print(file, > > > > > StandardCharsets.UTF_16BE)) { > > > > > + printer.printRecord("a", "b\\c"); > > > > > + } > > > > > + assertEquals("a,b\\c" + recordSeparator, > > > > > FileUtils.readFileToString(file, StandardCharsets.UTF_16BE)); > > > > > + } > > > > > + > > > > > + @Test > > > > > public void testPrintCustomNullValues() throws IOException { > > > > > final StringWriter sw = new StringWriter(); > > > > > try (final CSVPrinter printer = new CSVPrinter(sw, > > > > > CSVFormat.DEFAULT.withNullString("NULL"))) { > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > E-Mail: garydgregory@gmail.com | ggregory@apache.org > > > Java Persistence with Hibernate, Second Edition > > > > > > JUnit in Action, Second Edition > > > Spring Batch in Action > > > Blog: http://garygregory.wordpress.com > > > Home: http://garygregory.com/ > > > Tweet! http://twitter.com/GaryGregory > > > > --001a114c8f967a431505353eed08--