Package com.csvreader

Examples of com.csvreader.CsvReader


  @Test
  public void test22() throws Exception {
    String data = "\"data \"\" here\"";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("\"data \"\" here\"", reader.get(0));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("\"data \"\" here\"", reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here


  @Test
  public void test23() throws Exception {
    String data = generateString('a', 75) + "," + generateString('b', 75);

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals(reader.get(0), generateString('a', 75));
    Assert.assertEquals(reader.get(1), generateString('b', 75));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(2, reader.getColumnCount());
    Assert.assertEquals(generateString('a', 75) + ","
        + generateString('b', 75), reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test24() throws Exception {
    String data = "1\r\n\r\n1";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("1", reader.get(0));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("1", reader.getRawRecord());
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("1", reader.get(0));
    Assert.assertEquals(1L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("1", reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test25() throws Exception {
    String data = "1\r\n# bunch of crazy stuff here\r\n1";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    reader.setUseComments(true);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("1", reader.get(0));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("1", reader.getRawRecord());
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("1", reader.get(0));
    Assert.assertEquals(1L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("1", reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test26() throws Exception {
    String data = "\"Mac \"The Knife\" Peter\",\"Boswell, Jr.\"";

    CsvReader reader = CsvReader.parse(data);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("Mac ", reader.get(0));
    Assert.assertEquals("Boswell, Jr.", reader.get(1));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(2, reader.getColumnCount());
    Assert.assertEquals("\"Mac \"The Knife\" Peter\",\"Boswell, Jr.\"",
        reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test27() throws Exception {
    String data = "\"1\",Bruce\r\n\"2\n\",Toni\r\n\"3\",Brian\r\n";

    CsvReader reader = CsvReader.parse(data);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("1", reader.get(0));
    Assert.assertEquals("Bruce", reader.get(1));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(2, reader.getColumnCount());
    Assert.assertEquals("\"1\",Bruce", reader.getRawRecord());
    Assert.assertTrue(reader.skipRecord());
    Assert.assertEquals("\"2\n\",Toni", reader.getRawRecord());
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("3", reader.get(0));
    Assert.assertEquals("Brian", reader.get(1));
    Assert.assertEquals(1L, reader.getCurrentRecord());
    Assert.assertEquals(2, reader.getColumnCount());
    Assert.assertEquals("\"3\",Brian", reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test28() throws Exception {
    String data = "\"bob said, \\\"Hey!\\\"\",2, 3 ";

    CsvReader reader = CsvReader.parse(data);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("bob said, \"Hey!\"", reader.get(0));
    Assert.assertEquals("2", reader.get(1));
    Assert.assertEquals("3", reader.get(2));
    Assert.assertEquals(',', reader.getDelimiter());
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(3, reader.getColumnCount());
    Assert.assertEquals("\"bob said, \\\"Hey!\\\"\",2, 3 ", reader
        .getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test29() throws Exception {
    String data = "\"double\\\"\\\"double quotes\"";

    CsvReader reader = CsvReader.parse(data);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("double\"\"double quotes", reader.get(0));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("\"double\\\"\\\"double quotes\"", reader
        .getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test30() throws Exception {
    String data = "\"double\\\\\\\\double backslash\"";

    CsvReader reader = CsvReader.parse(data);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("double\\\\double backslash", reader.get(0));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("\"double\\\\\\\\double backslash\"", reader
        .getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

    // writer will trim all whitespace and put this in quotes to preserve
    // it's existance
    writer.write(" \t \t");
    writer.close();

    CsvReader reader = new CsvReader(new InputStreamReader(
        new FileInputStream("temp.csv"), Charset.forName("UTF-8")));
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("", reader.get(0));
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals("\"\"", reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();

    new File("temp.csv").delete();
  }
View Full Code Here

TOP

Related Classes of com.csvreader.CsvReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.