You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "saitouena (Jira)" <ji...@apache.org> on 2019/09/05 01:20:00 UTC

[jira] [Comment Edited] (CSV-251) CSVPrinter don't handle byte[] correctly for postgres

    [ https://issues.apache.org/jira/browse/CSV-251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16922972#comment-16922972 ] 

saitouena edited comment on CSV-251 at 9/5/19 1:19 AM:
-------------------------------------------------------

I'm not familiar with commons-csv, so I'm not sure this should be handled in commons-csv. That's why I submitted this as improvement (not as a bug). Any ideas?


was (Author: saitouena):
I'm not familiar with commons-csv, so I'm not sure this should be handled in commons-csv. Any ideas?

> CSVPrinter don't handle byte[] correctly for postgres
> -----------------------------------------------------
>
>                 Key: CSV-251
>                 URL: https://issues.apache.org/jira/browse/CSV-251
>             Project: Commons CSV
>          Issue Type: Improvement
>          Components: Printer
>         Environment: java version
> ```
> openjdk version "1.8.0_222"
> OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
> OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
> ```
> apache.commons.csv: 1.6
> clojure: 1.9.0
> postgres: 10.7
>  
>            Reporter: saitouena
>            Priority: Minor
>
> I passed byte[] values for CSVPrinter.printRecords with CSVFormat.POSTGRESQL_CSV, but it use Object.toString(printed [B@xxxx in clojure). As a result, data were discarded.
> I don't know about other RDBs, but at least postgres supports [https://www.postgresql.org/docs/9.3/datatype-binary.html] hexstring format.
> Workaround: Wrap byte[] with the class that has proper toString method like this.
> ```
> public string toString()
> { return "\\x" + encodeHexString(this.bytedata); }
> ```
> I used apache.commons.csv from Clojure. I'll make a minimal repro case in Java if needed. I have clojure code for now.
> clojure code:
> ```
> (deftype ByteArrayForCopyIn [^"[B" bs]
>  Object
>  (toString [self] (str "\\x" (Hex/encodeHexString bs))))
> (let [sb (StringBuilder.)
>  values [(.getBytes "hoge")]]
>  (with-open [^CSVPrinter p (CSVPrinter. sb CSVFormat/POSTGRESQL_CSV)]
>  (.printRecords p values)))
> ```
>  



--
This message was sent by Atlassian Jira
(v8.3.2#803003)