Skip to content

Commit

Permalink
rollback FileUtilities
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleValentini1 committed Sep 24, 2024
1 parent 2e0ca82 commit 84670c9
Showing 1 changed file with 0 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,12 @@ public static String toHexString(byte[] hash) {

public static File fromStringToFile(String fileBase64) {
try {

fileBase64 = fileBase64.replace('-', '+').replace('_', '/');

byte[] decodedBytes = Base64.getDecoder().decode(fileBase64);

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

setPermissions(tempDir);

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 @@ -127,16 +116,5 @@ public static File fromStringToFile(String fileBase64) {
}
}

private static void setPermissions(Path tempDir) throws IOException {
try {
Set<PosixFilePermission> perms = EnumSet.of(PosixFilePermission.OWNER_READ,
PosixFilePermission.OWNER_WRITE,
PosixFilePermission.OWNER_EXECUTE);
Files.setPosixFilePermissions(tempDir, perms);
} catch (UnsupportedOperationException e) {
log.warn("Posix file permissions are not supported on this system.");
}
}


}

0 comments on commit 84670c9

Please sign in to comment.