Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
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)))
```