private void testNull() throws Exception {
  deleteDb("csv");
  String fileName=getBaseDir() + "/testNull.csv";
  FileUtils.delete(fileName);
  OutputStream out=FileUtils.newOutputStream(fileName,false);
  String csvContent="\"A\",\"B\",\"C\",\"D\"\n\\N,\"\",\"\\N\",";
  byte[] b=csvContent.getBytes("UTF-8");
  out.write(b,0,b.length);
  out.close();
  Csv csv=new Csv();
  csv.setNullString("\\N");
  ResultSet rs=csv.read(fileName,null,"UTF8");
  ResultSetMetaData meta=rs.getMetaData();
  assertEquals(4,meta.getColumnCount());
  assertEquals("A",meta.getColumnLabel(1));
  assertEquals("B",meta.getColumnLabel(2));
  assertEquals("C",meta.getColumnLabel(3));
  assertEquals("D",meta.getColumnLabel(4));
  assertTrue(rs.next());
  assertEquals(null,rs.getString(1));
  assertEquals("",rs.getString(2));
  assertEquals("\\N",rs.getString(3));
  assertEquals(null,rs.getString(4));
  assertFalse(rs.next());
  Connection conn=getConnection("csv");
  Statement stat=conn.createStatement();
  stat.execute("call csvwrite('" + fileName + "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', "+ "'UTF8', ',', '\"', NULL, '\\N', '\n')");
  InputStreamReader reader=new InputStreamReader(FileUtils.newInputStream(fileName));
  String data=IOUtils.readStringAndClose(reader,-1);
  assertEquals(csvContent + "\\N",data.trim());
  conn.close();
  FileUtils.delete(fileName);
}

private void testNull ( ) throws Exception { deleteDb ( "csv" ) ; String fileName = getBaseDir ( ) + "/testNull.csv" ; FileUtils . delete ( fileName ) ; OutputStream out = FileUtils . newOutputStream ( fileName , false ) ; String csvContent = "\"A\",\"B\",\"C\",\"D\"\n\\N,\"\",\"\\N\"," ; byte [ ] b = csvContent . getBytes ( "UTF-8" ) ; out . write ( b , 0 , b . length ) ; out . close ( ) ; Csv csv = new Csv ( ) ; csv . setNullString ( "\\N" ) ; ResultSet rs = csv . read ( fileName , null , "UTF8" ) ; ResultSetMetaData meta = rs . getMetaData ( ) ; assertEquals ( 4 , meta . getColumnCount ( ) ) ; assertEquals ( "A" , meta . getColumnLabel ( 1 ) ) ; assertEquals ( "B" , meta . getColumnLabel ( 2 ) ) ; assertEquals ( "C" , meta . getColumnLabel ( 3 ) ) ; assertEquals ( "D" , meta . getColumnLabel ( 4 ) ) ; assertTrue ( rs . next ( ) ) ; assertEquals ( null , rs . getString ( 1 ) ) ; assertEquals ( "" , rs . getString ( 2 ) ) ; assertEquals ( "\\N" , rs . getString ( 3 ) ) ; assertEquals ( null , rs . getString ( 4 ) ) ; assertFalse ( rs . next ( ) ) ; Connection conn = getConnection ( "csv" ) ; Statement stat = conn . createStatement ( ) ; stat . execute ( "call csvwrite('" + fileName + "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', " + "'UTF8', ',', '\"', NULL, '\\N', '\n')" ) ; InputStreamReader reader = new InputStreamReader ( FileUtils . newInputStream ( fileName ) ) ; String data = IOUtils . readStringAndClose ( reader , - 1 ) ; assertEquals ( csvContent + "\\N" , data . trim ( ) ) ; conn . close ( ) ; FileUtils . delete ( fileName ) ; }
test custom null string .
