{"id":2253,"date":"2023-03-10T16:50:36","date_gmt":"2023-03-10T08:50:36","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=2253"},"modified":"2023-10-31T15:41:34","modified_gmt":"2023-10-31T07:41:34","slug":"java-create-csv-files-with-bom","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=2253","title":{"rendered":"[Java] Create CSV files with BOM"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public static final String UTF8_BOM = &quot;\\uFEFF&quot;;\n\npublic ByteArrayInputStream createFile(Object object) {\n    try {\n        CSV csv = (CSV) object;\n        StringBuffer sb = new StringBuffer();\n        sb.append(UTF8_BOM);\n\n        if (csv.getHeaderList() != null) {\n            sb.append(StringUtils.join(csv.getHeaderList().toArray(new String[0]), &quot;,&quot;)).append(&quot;\\n&quot;);\n        }\n\n        for (List&lt;String&gt; row : csv.getDataList()) {\n            sb.append(StringUtils.join(row.toArray(new String[0]), &quot;,&quot;)).append(&quot;\\n&quot;);\n        }\n\n        return new ByteArrayInputStream(sb.toString().getBytes(&quot;UTF-8&quot;));\n    } catch (Exception e) {\n        return null;\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public static final String UTF8_BOM = &quot;\\uFEFF&quot;; public ByteArrayInputStream createFile(Object object) { try { CSV csv = (CSV) object; StringBuffer sb = new StringBuffer(); sb.append(UTF8_BOM); if (csv.getHeaderList() != null) { sb.append(StringUtils.join(csv.getHeaderList().toArray(new String[0]), &quot;,&quot;)).append(&quot;\\n&quot;); } for (List&lt;String&gt; row : csv.getDataList()) { &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=2253\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-2253","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2253"}],"version-history":[{"count":1,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2253\/revisions"}],"predecessor-version":[{"id":2254,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2253\/revisions\/2254"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}