Metrics CSV writer: create parent directory if it does not exist

This commit is contained in:
Maximilian Kratz 2024-06-28 08:01:36 +02:00
parent 0d72cdd5f6
commit 10ea05aace
2 changed files with 20 additions and 0 deletions

2
.gitignore vendored
View file

@ -143,3 +143,5 @@ org.emoflon.gips.gipsl.examples.mdvne.seq/
org.emoflon.gips.gipsl.examples.mdvne.bwignore/
vne.scenarios/model.xmi
vne.scenarios/metrics/

View file

@ -1,6 +1,7 @@
package scenario.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
@ -237,6 +238,23 @@ public class CsvUtil {
return;
}
if (format == null) {
throw new IllegalArgumentException("Given CSV format was null");
}
if (content == null || content.length == 0) {
throw new IllegalArgumentException("Given content was null or empty.");
}
// Create parent folder if it does not exist
final int lastSlash = csvPath.lastIndexOf('/');
final String parentPath = csvPath.substring(0, lastSlash);
final File parentFolder = new File(parentPath);
if (!parentFolder.exists()) {
parentFolder.mkdir();
}
// Write CSV line itself
try {
BufferedWriter out;
// If file does not exist, write header to it