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

Gary Gregory commented on CSV-251:
----------------------------------

ATM, Commons CSV does not depend on Commons Codec which contains the Hex class. 

I am not sure we should copy and past this code here or depend on Commons Codec 
as a Maven dependency. I usually favor dependencies over copying code. Any 
thoughts from the community?

> 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)

Reply via email to