Package com.csvreader

Examples of com.csvreader.CsvReader$RawRecordBuffer


  @Test
  public void test32() 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


    String fileName = "somefile.csv";

    new File(fileName).createNewFile();

    try {
      CsvReader reader = new CsvReader(fileName);
      reader.close();
    } finally {
      new File(fileName).delete();
    }
  }
View Full Code Here

  @Test
  public void test34() throws Exception {
    String data = "\"Chicane\", \"Love on the Run\", \"Knight Rider\", \"This field contains a comma, but it doesn't matter as the field is quoted\"\r\n"
        + "\"Samuel Barber\", \"Adagio for Strings\", \"Classical\", \"This field contains a double quote character, \"\", but it doesn't matter as it is escaped\"";

    CsvReader reader = CsvReader.parse(data);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("Chicane", reader.get(0));
    Assert.assertEquals("Love on the Run", reader.get(1));
    Assert.assertEquals("Knight Rider", reader.get(2));
    Assert
        .assertEquals(
            "This field contains a comma, but it doesn't matter as the field is quoted",
            reader.get(3));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    Assert
        .assertEquals(
            "\"Chicane\", \"Love on the Run\", \"Knight Rider\", \"This field contains a comma, but it doesn't matter as the field is quoted\"",
            reader.getRawRecord());
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("Samuel Barber", reader.get(0));
    Assert.assertEquals("Adagio for Strings", reader.get(1));
    Assert.assertEquals("Classical", reader.get(2));
    Assert
        .assertEquals(
            "This field contains a double quote character, \", but it doesn't matter as it is escaped",
            reader.get(3));
    Assert.assertEquals(1L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    Assert
        .assertEquals(
            "\"Samuel Barber\", \"Adagio for Strings\", \"Classical\", \"This field contains a double quote character, \"\", but it doesn't matter as it is escaped\"",
            reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test35() throws Exception {
    String data = "Chicane, Love on the Run, Knight Rider, \"This field contains a comma, but it doesn't matter as the field is quoted\"";

    CsvReader reader = CsvReader.parse(data);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("Chicane", reader.get(0));
    Assert.assertEquals("Love on the Run", reader.get(1));
    Assert.assertEquals("Knight Rider", reader.get(2));
    Assert
        .assertEquals(
            "This field contains a comma, but it doesn't matter as the field is quoted",
            reader.get(3));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    Assert
        .assertEquals(
            "Chicane, Love on the Run, Knight Rider, \"This field contains a comma, but it doesn't matter as the field is quoted\"",
            reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test36() throws Exception {
    String data = "\"some \\stuff\"";

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

  @Test
  public void test37() throws Exception {
    String data = "  \" Chicane\"  junk here  , Love on the Run, Knight Rider, \"This field contains a comma, but it doesn't matter as the field is quoted\"";

    CsvReader reader = CsvReader.parse(data);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals(" Chicane", reader.get(0));
    Assert.assertEquals("Love on the Run", reader.get(1));
    Assert.assertEquals("Knight Rider", reader.get(2));
    Assert
        .assertEquals(
            "This field contains a comma, but it doesn't matter as the field is quoted",
            reader.get(3));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    Assert
        .assertEquals(
            "  \" Chicane\"  junk here  , Love on the Run, Knight Rider, \"This field contains a comma, but it doesn't matter as the field is quoted\"",
            reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

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

    CsvReader reader = CsvReader.parse(data);
    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("", reader.get(0));
    Assert.assertEquals(1L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("\"\"", reader.getRawRecord());
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("", reader.get(0));
    Assert.assertEquals(2L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals(" ", reader.getRawRecord());
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("2", reader.get(0));
    Assert.assertEquals(3L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertEquals("2", reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

    reader.close();
  }

  @Test
  public void test39() throws Exception {
    CsvReader reader = CsvReader.parse("user_id,name\r\n1,Bruce");
    Assert.assertTrue(reader.getSafetySwitch());
    reader.setSafetySwitch(false);
    Assert.assertFalse(reader.getSafetySwitch());

    Assert.assertEquals('#', reader.getComment());
    reader.setComment('!');
    Assert.assertEquals('!', reader.getComment());

    Assert.assertEquals(CsvReader.ESCAPE_MODE_DOUBLED, reader
        .getEscapeMode());
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertEquals(CsvReader.ESCAPE_MODE_BACKSLASH, reader
        .getEscapeMode());

    Assert.assertEquals('\0', reader.getRecordDelimiter());
    reader.setRecordDelimiter(';');
    Assert.assertEquals(';', reader.getRecordDelimiter());

    Assert.assertEquals('\"', reader.getTextQualifier());
    reader.setTextQualifier('\'');
    Assert.assertEquals('\'', reader.getTextQualifier());

    Assert.assertTrue(reader.getTrimWhitespace());
    reader.setTrimWhitespace(false);
    Assert.assertFalse(reader.getTrimWhitespace());

    Assert.assertFalse(reader.getUseComments());
    reader.setUseComments(true);
    Assert.assertTrue(reader.getUseComments());

    Assert.assertTrue(reader.getUseTextQualifier());
    reader.setUseTextQualifier(false);
    Assert.assertFalse(reader.getUseTextQualifier());
    reader.close();
  }
View Full Code Here

  @Test
  public void test40() throws Exception {
    String data = "Chicane, Love on the Run, Knight Rider, This field contains a comma\\, but it doesn't matter as the delimiter is escaped";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("Chicane", reader.get(0));
    Assert.assertEquals("Love on the Run", reader.get(1));
    Assert.assertEquals("Knight Rider", reader.get(2));
    Assert
        .assertEquals(
            "This field contains a comma, but it doesn't matter as the delimiter is escaped",
            reader.get(3));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    Assert
        .assertEquals(
            "Chicane, Love on the Run, Knight Rider, This field contains a comma\\, but it doesn't matter as the delimiter is escaped",
            reader.getRawRecord());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

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

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    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.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

TOP

Related Classes of com.csvreader.CsvReader$RawRecordBuffer

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.