Skip to content
Permalink
Browse files
better validation for DefaultMapper and allowing to create parent in …
…CommonsCsvWriter
  • Loading branch information
Romain Manni-Bucau committed Nov 20, 2015
1 parent c30a639 commit e37f9e1ba9f980ef344c9ac71de0f4b68dc974d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
@@ -127,7 +127,11 @@ public void open(final Serializable checkpoint) throws Exception {
}
final CSVFormat format = newFormat();

this.transactionalWriter = new TransactionalWriter(new File(output), encoding, checkpoint);
final File file = new File(output);
if (!file.exists() && !file.getParentFile().mkdirs()) {
throw new IllegalStateException("Cant create " + file);
}
this.transactionalWriter = new TransactionalWriter(file, encoding, checkpoint);
this.writer = format.print(transactionalWriter);
}

@@ -52,12 +52,16 @@ public DefaultMapper(final Class<T> type) {

// put each field a single time to avoid to set it twice even if position and name are filled for header output
if (pos >= 0) {
fieldByPosition.put(pos, field);
if (fieldByPosition.put(pos, field) != null) {
throw new IllegalArgumentException("multiple field for index " + pos + " in " + type);
}
if (!defaultName) {
headers.put(pos, name);
}
} else if (!defaultName) {
fieldByName.put(name, field);
if (fieldByName.put(name, field) != null) {
throw new IllegalArgumentException("multiple field for name '" + name + "' in " + type);
}
}
if (pos > higherIdx) {
higherIdx = pos;

0 comments on commit e37f9e1

Please sign in to comment.