mosquito87
mosquito87

Reputation: 4440

Export csv with UTF-8 encoding

I want to ensure that my written CSV-file is encoded using UTF-8:

public StreamResource getExportDataAsCsv() {
    return new StreamResource(new StreamResource.StreamSource() {
        @Override
        public InputStream getStream() {
            List<Object[]> exportData = getExportData();
            StringBuffer buffer = new StringBuffer();

            buffer.append(someData);
            byte[] bytes = buffer.toString().getBytes();

            return new ByteArrayInputStream(bytes);
        }
    }, "MyExport.csv");
}

Unfortunately the found methods/ways to do so don't fit to my interface. Any ideas?

Upvotes: 0

Views: 3443

Answers (1)

stevops
stevops

Reputation: 439

buffer.toString().getBytes("UTF-8");

Upvotes: 1

Related Questions