CsvUtils { public static String escapeCsvData(String data) { ByteArrayOutputStream out = new ByteArrayOutputStream(); CsvWriter writer = new CsvWriter(new OutputStreamWriter(out), ','); writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH); try { writer.write(data); writer.close(); out.close(); } catch (IOException e) { } return out.toString(); }  static CsvReader getCsvReader(Reader reader); static CsvReader getCsvReaderDquote(Reader reader); static String[] tokenizeCsvData(String csvData); static String escapeCsvData(String data); static String escapeAndQuoteCsvData(String data); static String escapeCsvData(String[] data); static String escapeCsvData(String[] data, char recordDelimiter, char textQualifier); static String escapeCsvData(String[] data, char recordDelimiter, char textQualifier, int escapeMode); static String escapeCsvData(String[] data, char recordDelimiter, char textQualifier, int escapeMode, String nullString); static int write(Writer writer, String... data); static void writeSql(String sql, Writer writer); static void writeBsh(String script, Writer writer); static void writeLineFeed(Writer writer); static final String DELIMITER; static final String LINE_SEPARATOR; }
@Test public void testEscapeDoubledSingleQuote() { assertEquals("'L\\'' Hospitalet',,'277000043'\n", CsvUtils.escapeCsvData(new String[] {"L\\' Hospitalet",null,"277000043"}, '\n', '\'', CsvWriter.ESCAPE_MODE_DOUBLED)); }