Skip to content

Commit

Permalink
Avoid multiple file creation on classpath property value
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Dec 5, 2024
1 parent 3f2e7da commit a92884f
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.commons.io.FileUtils;
Expand All @@ -25,11 +24,12 @@ public String getProperty(final String key) {
if(value != null && value.startsWith("classpath:")) {
try {
final String classpathResource = StringUtils.removeStart(value, "classpath:");
final String extension = FilenameUtils.getExtension(classpathResource);
final String baseName = FilenameUtils.getBaseName(classpathResource);
final File tempFile = Files.createTempFile(appRootDir, baseName, "."+extension).toFile();
FileUtils.copyURLToFile(getClass().getResource(classpathResource), tempFile);
return tempFile.getAbsolutePath();
final String name = FilenameUtils.getName(classpathResource);
final File file = appRootDir.resolve(name).toFile();
if(!file.exists()) {
FileUtils.copyURLToFile(getClass().getResource(classpathResource), file);
}
return file.getAbsolutePath();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit a92884f

Please sign in to comment.