You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/06/06 15:45:28 UTC
[camel] 01/02: CAMEL-19421 - Camel-Jira: Use Files.createTempFile in FileConverter instead of creating File directly
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit b61d5b6be4f98b673dc977ad1bc6f004642644ab
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Jun 6 17:06:33 2023 +0200
CAMEL-19421 - Camel-Jira: Use Files.createTempFile in FileConverter instead of creating File directly
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../org/apache/camel/component/jira/FileConverter.java | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
index d7d2f3642d7..e19d85e4ef9 100644
--- a/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/FileConverter.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jira;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.apache.camel.Converter;
@@ -34,20 +35,13 @@ public final class FileConverter {
@Converter
public static File genericToFile(GenericFile<File> genericFile, Exchange exchange) throws IOException {
Object body = genericFile.getBody();
- File file;
+ File file = null;
+ Path path;
if (body instanceof byte[]) {
byte[] bos = (byte[]) body;
- String destDir = System.getProperty("java.io.tmpdir");
- if (destDir != null && !destDir.endsWith(File.separator)) {
- destDir += File.separator;
- }
- file = new File(destDir, genericFile.getFileName());
- if (!file.getCanonicalPath().startsWith(destDir)) {
- throw new IOException("File is not jailed to the destination directory");
- }
- Files.write(file.toPath(), bos, StandardOpenOption.CREATE);
- // delete the temporary file on exit, as other routing may need the file for post processing
- file.deleteOnExit();
+ path = Files.createTempFile(genericFile.getFileName(), null, null);
+ Files.write(path, bos, StandardOpenOption.CREATE);
+ path.toFile().deleteOnExit();
} else {
file = (File) body;
}