Package com.csvreader

Examples of com.csvreader.CsvReader$RawRecordBuffer


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

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


  @Test
  public void test43() throws Exception {
    String data = "\"line 1\\nline 2\",\"line 1\\\nline 2\"";

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

  @Test
  public void test44() throws Exception {
    String data = "line 1\\nline 2,line 1\\\nline 2";

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

  @Test
  public void test45() 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\"i"
        + "\"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.getCaptureRawRecord());
    reader.setCaptureRawRecord(false);
    Assert.assertFalse(reader.getCaptureRawRecord());
    Assert.assertEquals("", reader.getRawRecord());
    reader.setRecordDelimiter('i');
    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("", reader.getRawRecord());
    Assert.assertFalse(reader.getCaptureRawRecord());
    reader.setCaptureRawRecord(true);
    Assert.assertTrue(reader.getCaptureRawRecord());
    Assert.assertTrue(reader.readRecord());
    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.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.assertFalse(reader.readRecord());
    Assert.assertTrue(reader.getCaptureRawRecord());
    Assert.assertEquals("", reader.getRawRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test46() throws Exception {
    String data = "Ch\\icane, Love on the Run, Kn\\ight R\\ider, Th\\is f\\ield conta\\ins an \\i\\, but \\it doesn't matter as \\it \\is escapedi"
        + "Samuel Barber, Adag\\io for Str\\ings, Class\\ical, Th\\is f\\ield conta\\ins a comma \\, but \\it doesn't matter as \\it \\is escaped";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    reader.setRecordDelimiter('i');
    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 an i, but it doesn't matter as it is escaped",
            reader.get(3));
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    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 comma , but it doesn't matter as it is escaped",
            reader.get(3));
    Assert.assertEquals(1L, reader.getCurrentRecord());
    Assert.assertEquals(4, reader.getColumnCount());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

    writer.close();

    buffer = stream.toByteArray();
    stream.close();

    CsvReader reader = new CsvReader(new InputStreamReader(
        new ByteArrayInputStream(buffer), Charset.forName("UTF-8")));
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals(test, reader.get(0));
    reader.close();
  }
View Full Code Here

    writer.close();

    buffer = stream.toByteArray();
    stream.close();

    CsvReader reader = new CsvReader(new InputStreamReader(
        new ByteArrayInputStream(buffer), Charset.forName("UTF-8")));
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals(test, reader.get(0));
    reader.close();
  }
View Full Code Here

  @Test
  public void test49() throws Exception {
    String data = "\"\\n\\r\\t\\b\\f\\e\\v\\a\\z\\d065\\o101\\101\\x41\\u0041\"";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(true);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert
        .assertEquals("\n\r\t\b\f\u001B\u000B\u0007zAAAAA", reader
            .get(0));
    Assert.assertEquals(
        "\"\\n\\r\\t\\b\\f\\e\\v\\a\\z\\d065\\o101\\101\\x41\\u0041\"",
        reader.getRawRecord());
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test50() throws Exception {
    String data = "\\n\\r\\t\\b\\f\\e\\v\\a\\z\\d065\\o101\\101\\x41\\u0041";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(false);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert
        .assertEquals("\n\r\t\b\f\u001B\u000B\u0007zAAAAA", reader
            .get(0));
    Assert.assertEquals(
        "\\n\\r\\t\\b\\f\\e\\v\\a\\z\\d065\\o101\\101\\x41\\u0041",
        reader.getRawRecord());
    Assert.assertEquals(0L, reader.getCurrentRecord());
    Assert.assertEquals(1, reader.getColumnCount());
    Assert.assertFalse(reader.readRecord());
    reader.close();
  }
View Full Code Here

  @Test
  public void test51() throws Exception {
    String data = "\"\\xfa\\u0afa\\xFA\\u0AFA\"";

    CsvReader reader = CsvReader.parse(data);
    reader.setUseTextQualifier(true);
    reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
    Assert.assertTrue(reader.readRecord());
    Assert.assertEquals("\u00FA\u0AFA\u00FA\u0AFA", reader.get(0));
    Assert.assertEquals("\"\\xfa\\u0afa\\xFA\\u0AFA\"", reader
        .getRawRecord());
    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.