Skip to content
Snippets Groups Projects
Commit 157c735a authored by Michal Badin's avatar Michal Badin
Browse files

fix(VisualizationService) : Correctly created output file in cross-platforms

parent 7b2b6e07
No related branches found
No related tags found
4 merge requests!54Merge develop into main,!48Scenario,!46Visualization pdf,!44Security
Pipeline #
This commit is part of merge request !44. Comments created here will be created in the context of that merge request.
......@@ -12,7 +12,9 @@ import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
@Service
public class VisualizationService {
......@@ -100,8 +102,19 @@ public class VisualizationService {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
document.save(baos);
String outputDirName = "output-data";
Path projectDir = Paths.get("").toAbsolutePath().getParent();
Path outputDirPath = projectDir.resolve(outputDirName);
// Create output directory if it does not exist
if (!Files.exists(outputDirPath)) {
Files.createDirectories(outputDirPath);
}
String outputFileName = String.format("car-%s.pdf", carDto.getId());
// Save generated file
Files.write(Paths.get(String.format("C:\\WORKSPACE\\car-%s.pdf", carDto.getId())), baos.toByteArray());
Files.write(outputDirPath.resolve(outputFileName), baos.toByteArray());
return new ByteArrayResource(baos.toByteArray());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment