CsvReportWriter { public void write(@NonNull String csv) throws IOException { try (FileOutputStream fileOutputStream = new FileOutputStream(this.outputFile)) { IOUtils.write(ByteOrderMark.UTF_8.getBytes(), fileOutputStream); IOUtils.write(csv, fileOutputStream, "UTF-8"); } } CsvReportWriter(@NonNull File outputFile); void write(@NonNull String csv);  }
@Test public void write() throws Exception { final String csv = "column1, column2, column3, column4,\nhello, שלום, привет, hello,"; writer.write(csv); try (BOMInputStream bomInputStream = new BOMInputStream(new FileInputStream(outputFile))) { final String fileString = IOUtils.toString(bomInputStream, "UTF-8"); assertEquals(fileString, csv); assertTrue(bomInputStream.hasBOM()); } }