Skip to content

Commit

Permalink
Fix sonar FileUtilities issue
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleValentini1 committed Sep 23, 2024
1 parent 3f69c17 commit 77eecbc
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.EnumSet;

import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_DOES_NOT_HAVE_DEFINITION_KEY;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.CANNOT_EXTRACT_FILE_DEFINITION_KEY;
Expand Down Expand Up @@ -98,11 +100,20 @@ public static String toHexString(byte[] hash) {
public static File fromStringToFile(String fileBase64) {
try {
byte[] decodedBytes = Base64.getDecoder().decode(fileBase64);

Path tempDir = Files.createTempDirectory("multipleUpload");

Files.setPosixFilePermissions(tempDir,
EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE));

File tempFile = File.createTempFile("tempfile", ".tmp", tempDir.toFile());

try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(decodedBytes);
}

tempFile.deleteOnExit();

return tempFile;
} catch (IllegalArgumentException e) {
log.error("Errore nella decodifica del Base64: " + e.getMessage());
Expand All @@ -114,4 +125,5 @@ public static File fromStringToFile(String fileBase64) {
}



}

0 comments on commit 77eecbc

Please sign in to comment.