diff --git a/components/camel-grape/src/main/java/org/apache/camel/component/grape/FilePatchesRepository.java b/components/camel-grape/src/main/java/org/apache/camel/component/grape/FilePatchesRepository.java index 92dcf6c95f3da..fc7503968e1bb 100644 --- a/components/camel-grape/src/main/java/org/apache/camel/component/grape/FilePatchesRepository.java +++ b/components/camel-grape/src/main/java/org/apache/camel/component/grape/FilePatchesRepository.java @@ -21,7 +21,6 @@ import java.io.IOError; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -73,7 +72,7 @@ public List listPatches() { @Override public void clear() { try { - Files.delete(repository.toPath()); + repository.delete(); repository.createNewFile(); } catch (IOException e) { throw new IOError(e); diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsNormalFileHandler.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsNormalFileHandler.java index dc2317cf1e677..75bddd4866a03 100644 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsNormalFileHandler.java +++ b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsNormalFileHandler.java @@ -155,9 +155,8 @@ private File getHdfsFileToTmpFile(String hdfsPath, HdfsConfiguration configurati } if (outputDest.exists()) { - try { - Files.delete(outputDest.toPath()); - } catch (IOException e) { + boolean result = outputDest.delete(); + if (!result) { LOG.error("Failed to delete output destination {}", outputDest); } } diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java index 865f2a57df97f..7f3bf2b45899c 100644 --- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java +++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/CamelFilterWrapper.java @@ -66,10 +66,8 @@ public void init(FilterConfig config) throws ServletException { //go ahead and set it to the default tmp dir on the system. try { File file = Files.createTempFile("camel", "").toFile(); - try { - Files.delete(file.toPath()); - } - catch(IOException e) { + boolean result = file.delete(); + if (!result) { LOG.error("failed to delete {}", file); } config.getServletContext().setAttribute("jakarta.servlet.context.tempdir", diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java index 0eb54fdd81486..b5c41f2caaf31 100644 --- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java +++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java @@ -23,7 +23,6 @@ import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.Files; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Arrays; @@ -1143,10 +1142,8 @@ protected CamelServlet createServletForConnector( context.addServlet(holder, "/*"); File file = File.createTempFile("camel", ""); - try { - Files.delete(file.toPath()); - } - catch(IOException e) { + boolean result = file.delete(); + if (!result) { LOG.error("failed to delete {}", file); } diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java index 5d0d0da633c9e..e0a1a2bfca567 100644 --- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java +++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java @@ -17,7 +17,6 @@ package org.apache.camel.component.rest.openapi; import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; @@ -80,6 +79,7 @@ import org.slf4j.LoggerFactory; import static java.util.Optional.ofNullable; + import static org.apache.camel.component.rest.openapi.RestOpenApiHelper.isHostParam; import static org.apache.camel.component.rest.openapi.RestOpenApiHelper.isMediaRange; import static org.apache.camel.util.ObjectHelper.isNotEmpty; @@ -802,7 +802,7 @@ static String hostFrom(final RestConfiguration restConfiguration) { * @param camelContext context to use * @return the specification */ - static OpenAPI loadSpecificationFrom(final CamelContext camelContext, final URI uri) throws IOException { + static OpenAPI loadSpecificationFrom(final CamelContext camelContext, final URI uri) { final String uriAsString = uri.toString(); final OpenAPIParser openApiParser = new OpenAPIParser(); final ParseOptions options = new ParseOptions(); @@ -835,7 +835,7 @@ static OpenAPI loadSpecificationFrom(final CamelContext camelContext, final URI "The given OpenApi specification could not be loaded from `" + uri + "`.", e); } finally { if (tmpFileToDelete != null) { - Files.delete(tmpFileToDelete.toPath()); + tmpFileToDelete.delete(); } } diff --git a/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java b/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java index 2a71d4566e8a7..2a16cf797961e 100644 --- a/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java +++ b/components/camel-tarfile/src/main/java/org/apache/camel/processor/aggregate/tarfile/TarAggregationStrategy.java @@ -206,7 +206,7 @@ public void onCompletion(Exchange exchange, Exchange inputExchange) { private void addFileToTar(File source, File file, String fileName) throws IOException, ArchiveException { File tmpTar = Files.createTempFile(parentDir.toPath(), source.getName(), null).toFile(); - Files.delete(tmpTar.toPath()); + tmpTar.delete(); if (!source.renameTo(tmpTar)) { throw new IOException("Could not make temp file (" + source.getName() + ")"); } @@ -251,7 +251,7 @@ private void copyExistingEntries(TarArchiveInputStream tin, TarArchiveOutputStre private void addEntryToTar(File source, String entryName, byte[] buffer, int length) throws IOException, ArchiveException { File tmpTar = Files.createTempFile(parentDir.toPath(), source.getName(), null).toFile(); - Files.delete(tmpTar.toPath()); + tmpTar.delete(); if (!source.renameTo(tmpTar)) { throw new IOException("Cannot create temp file: " + source.getName()); } diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategy.java b/components/camel-zipfile/src/main/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategy.java index 49ce0237427bd..5b59f2eee7bbe 100644 --- a/components/camel-zipfile/src/main/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategy.java +++ b/components/camel-zipfile/src/main/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategy.java @@ -224,7 +224,7 @@ public void onCompletion(Exchange exchange, Exchange inputExchange) { } private static void newZipFile(File zipFile) throws URISyntaxException, IOException { - if (zipFile.exists() && !Files.deleteIfExists(zipFile.toPath())) { //Delete, because ZipFileSystem needs to create file on its own (with correct END bytes in the file) + if (zipFile.exists() && !zipFile.delete()) { //Delete, because ZipFileSystem needs to create file on its own (with correct END bytes in the file) throw new IOException("Cannot delete file " + zipFile); } Map env = new HashMap<>(); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java index 67d4dc6072088..3c718fe5ecaa5 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java @@ -1293,7 +1293,7 @@ private void writeSettings(String key, String value) { } } - private static void removeDir(File d) throws IOException { + private static void removeDir(File d) { String[] list = d.list(); if (list == null) { list = new String[0]; @@ -1309,14 +1309,14 @@ private static void removeDir(File d) throws IOException { delete(d); } - private static void delete(File f) throws IOException { - if (!Files.deleteIfExists(f.toPath())) { + private static void delete(File f) { + if (!f.delete()) { try { Thread.sleep(10); } catch (InterruptedException ex) { // Ignore Exception } - if (!Files.deleteIfExists(f.toPath())) { + if (!f.delete()) { f.deleteOnExit(); } }