You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Benedikt Ritter <br...@apache.org> on 2014/06/30 22:04:56 UTC

Re: svn commit: r1606616 - /commons/proper/csv/trunk/src/site/xdoc/index.xml

Nice!


2014-06-30 3:42 GMT+02:00 <gg...@apache.org>:

> Author: ggregory
> Date: Mon Jun 30 01:42:46 2014
> New Revision: 1606616
>
> URL: http://svn.apache.org/r1606616
> Log:
> Document how to handle BOMs. See also     [CSV-107] CSVFormat.EXCEL.parse
> should handle byte order marks.
>
> Modified:
>     commons/proper/csv/trunk/src/site/xdoc/index.xml
>
> Modified: commons/proper/csv/trunk/src/site/xdoc/index.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/site/xdoc/index.xml?rev=1606616&r1=1606615&r2=1606616&view=diff
>
> ==============================================================================
> --- commons/proper/csv/trunk/src/site/xdoc/index.xml (original)
> +++ commons/proper/csv/trunk/src/site/xdoc/index.xml Mon Jun 30 01:42:46
> 2014
> @@ -32,7 +32,28 @@ for (CSVRecord record : records) {
>    String firstName = record.get("First Name");
>  }</source>
>    <p>Other formats are available, please consult the Javadoc for <a
> href="apidocs/org/apache/commons/csv/CSVFormat.html">CSVFormat</a> and
> -  <a
> href="apidocs/org/apache/commons/csv/CSVParser.html">CSVParser</a>.</p>
> +    <a href="apidocs/org/apache/commons/csv/CSVParser.html">CSVParser</a>.
> +  </p>
> +</section>
> +<section name="Handling Byte Order Marks">
> +  <p>
> +    To handle files that start with a Byte Order Mark (BOM) like some
> Excel CSV files, you need an extra step to deal with these optional bytes.
> +    You can use the
> +    <a href="
> https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/BOMInputStream.html
> ">BOMInputStream</a>
> +    class from <a href="https://commons.apache.org/proper/commons-io/">Apache
> Commons IO</a> for example:
> +  </p>
> +  <source>final URL url = ...;
> +final Reader reader = new InputStreamReader(new
> BOMInputStream(url.openStream()), "UTF-8");
> +final CSVParser parser = new CSVParser(reader,
> CSVFormat.EXCEL.withHeader());
> +try {
> +  for (final CSVRecord record : parser) {
> +    final String string = record.get("SomeColumn");
> +    ...
> +  }
> +} finally {
> +  parser.close();
> +  reader.close();
> +}</source>
>  </section>
>
>  <section name="Getting the code">
>
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter