Exemplo n.º 1
0
 public CSVFormat getCSVFormat() {
   return CSVFormat.DEFAULT
       .withDelimiter(delimiter)
       .withRecordSeparator(recordSeparator)
       .withNullString(nullString)
       .withEscape(escapeCharacter)
       .withQuote(quoteCharacter)
       .withQuoteMode(quoteMode);
 }
Exemplo n.º 2
0
 private List<Measurement> readMeasurements(String measurementCsvLocation) {
   List<Measurement> measurements = new ArrayList<>();
   try (Reader in = new FileReader(measurementCsvLocation)) {
     Iterable<CSVRecord> records = CSVFormat.DEFAULT.withDelimiter(';').parse(in);
     for (CSVRecord record : records) {
       Long timeStamp = Long.parseLong(record.get(0));
       Double temperature = Double.parseDouble(record.get(1));
       measurements.add(new Measurement(timeStamp, temperature));
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return measurements;
 }
  @Test
  public void testApacheCommonCsvDelimiter() throws Exception {
    StringReader stringReader = new StringReader("foo;bar;15;true");
    CSVFormat csvFormat =
        CSVFormat.DEFAULT.withDelimiter(';').withHeader("firstName", "lastName", "age", "married");
    ApacheCommonCsvRecord record = getApacheCommonCsvRecord(stringReader, csvFormat);

    Foo foo = mapper.mapRecord(record);

    assertThat(foo).isNotNull();
    assertThat(foo.getFirstName()).isEqualTo("foo");
    assertThat(foo.getLastName()).isEqualTo("bar");
    assertThat(foo.getAge()).isEqualTo(15);
    assertThat(foo.isMarried()).isTrue();
  }
Exemplo n.º 4
0
 @Test(expected = IllegalArgumentException.class)
 public void testDelimiterSameAsEscapeThrowsException() {
   CSVFormat.DEFAULT.withDelimiter('!').withEscape('!');
 }
Exemplo n.º 5
0
 @Test(expected = IllegalArgumentException.class)
 public void testDelimiterSameAsCommentStartThrowsException() {
   CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!');
 }
Exemplo n.º 6
0
 @Test(expected = IllegalArgumentException.class)
 public void testWithDelimiterLFThrowsException() {
   CSVFormat.DEFAULT.withDelimiter(LF);
 }
Exemplo n.º 7
0
 @Test
 public void testWithDelimiter() throws Exception {
   final CSVFormat formatWithDelimiter = CSVFormat.DEFAULT.withDelimiter('!');
   assertEquals('!', formatWithDelimiter.getDelimiter());
 }
Exemplo n.º 8
0
 protected CSVFormat getFormat() {
   return CSVFormat.DEFAULT.withDelimiter(';').withRecordSeparator('\n');
 }