You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/06/12 07:57:44 UTC
[camel] 01/01: CAMEL-19435: camel-core - Remove converter: String -> java.io.File
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch ioc
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 38f26ca252becd4de3e69c23c607c77c9b72913c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jun 12 09:57:18 2023 +0200
CAMEL-19435: camel-core - Remove converter: String -> java.io.File
---
.../camel/component/file/FileOperations.java | 45 +++++++-------
.../GenericFileProcessStrategySupport.java | 11 ++--
.../FromFileToFtpDefaultRootRenameStrategyIT.java | 3 +-
.../FromFtpDirectoryToBinaryFilesIT.java | 5 +-
.../FromFtpSetNamesWithMultiDirectoriesIT.java | 5 +-
.../remote/integration/FromFtpToBinaryFileIT.java | 3 +-
.../remote/integration/FromFtpToBinaryFilesIT.java | 5 +-
.../FtpSimpleConsumeStreamingStepwiseIT.java | 4 +-
.../converter/CamelBaseBulkConverterLoader.java | 16 ++---
.../org/apache/camel/converter/IOConverter.java | 72 +++++++++++-----------
.../org/apache/camel/converter/ConverterTest.java | 7 ---
.../ROOT/pages/camel-4-migration-guide.adoc | 4 ++
12 files changed, 89 insertions(+), 91 deletions(-)
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
index 353246ea9ab..e8867fae354 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -321,30 +321,33 @@ public class FileOperations implements GenericFileOperations<File> {
// a full file to file copy, as the local work copy is to be
// deleted afterwards anyway
// local work path
- File local = exchange.getIn().getHeader(FileConstants.FILE_LOCAL_WORK_PATH, File.class);
- if (local != null && local.exists()) {
- boolean renamed = writeFileByLocalWorkPath(local, file);
- if (renamed) {
- // try to keep last modified timestamp if configured to
- // do so
- keepLastModified(exchange, file);
- // set permissions if the chmod option was set
- if (ObjectHelper.isNotEmpty(endpoint.getChmod())) {
- Set<PosixFilePermission> permissions = endpoint.getPermissions();
- if (!permissions.isEmpty()) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Setting chmod: {} on file: {}", PosixFilePermissions.toString(permissions),
- file);
+ String local = exchange.getIn().getHeader(FileConstants.FILE_LOCAL_WORK_PATH, String.class);
+ if (local != null) {
+ File f = new File(local);
+ if (f.exists()) {
+ boolean renamed = writeFileByLocalWorkPath(f, file);
+ if (renamed) {
+ // try to keep last modified timestamp if configured to
+ // do so
+ keepLastModified(exchange, file);
+ // set permissions if the chmod option was set
+ if (ObjectHelper.isNotEmpty(endpoint.getChmod())) {
+ Set<PosixFilePermission> permissions = endpoint.getPermissions();
+ if (!permissions.isEmpty()) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Setting chmod: {} on file: {}", PosixFilePermissions.toString(permissions),
+ file);
+ }
+ Files.setPosixFilePermissions(file.toPath(), permissions);
}
- Files.setPosixFilePermissions(file.toPath(), permissions);
}
+ // clear header as we have renamed the file
+ exchange.getIn().setHeader(FileConstants.FILE_LOCAL_WORK_PATH, null);
+ // return as the operation is complete, we just renamed
+ // the local work file
+ // to the target.
+ return true;
}
- // clear header as we have renamed the file
- exchange.getIn().setHeader(FileConstants.FILE_LOCAL_WORK_PATH, null);
- // return as the operation is complete, we just renamed
- // the local work file
- // to the target.
- return true;
}
} else if (source != null && source.exists()) {
// no there is no local work file so use file to file copy
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
index 4ef342f9894..cafdd64956d 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
@@ -153,10 +153,13 @@ public abstract class GenericFileProcessStrategySupport<T> extends ServiceSuppor
protected void deleteLocalWorkFile(Exchange exchange) {
// delete local work file, if it was used (eg by ftp component)
- File local = exchange.getIn().getHeader(FileConstants.FILE_LOCAL_WORK_PATH, File.class);
- if (local != null && local.exists()) {
- boolean deleted = FileUtil.deleteFile(local);
- LOG.trace("Local work file: {} was deleted: {}", local, deleted);
+ String local = exchange.getIn().getHeader(FileConstants.FILE_LOCAL_WORK_PATH, String.class);
+ if (local != null) {
+ File f = new File(local);
+ if (f.exists()) {
+ boolean deleted = FileUtil.deleteFile(f);
+ LOG.trace("Local work file: {} was deleted: {}", local, deleted);
+ }
}
}
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
index f9011fcc119..41d4c9380d5 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpDefaultRootRenameStrategyIT.java
@@ -24,7 +24,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -77,7 +76,7 @@ public class FromFileToFtpDefaultRootRenameStrategyIT extends FtpServerTestSuppo
// create a binary file .. uploaded to the default root location
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo.jpeg"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo.jpeg");
Producer producer = endpoint.createProducer();
producer.start();
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDirectoryToBinaryFilesIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDirectoryToBinaryFilesIT.java
index 65290d61254..a603c9895bd 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDirectoryToBinaryFilesIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpDirectoryToBinaryFilesIT.java
@@ -22,7 +22,6 @@ import java.nio.file.Path;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
import org.apache.camel.test.junit5.TestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -52,10 +51,10 @@ public class FromFtpDirectoryToBinaryFilesIT extends FtpServerTestSupport {
@BeforeAll
public static void gatherFileInfo() {
- logoFile = IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg");
+ logoFile = new File("src/test/data/ftpbinarytest/logo.jpeg");
logoFileSize = logoFile.length();
- logo1File = IOConverter.toFile("src/test/data/ftpbinarytest/logo1.jpeg");
+ logo1File = new File("src/test/data/ftpbinarytest/logo1.jpeg");
logo1FileSize = logo1File.length();
}
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSetNamesWithMultiDirectoriesIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSetNamesWithMultiDirectoriesIT.java
index ac79f7c8e7c..150391008a4 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSetNamesWithMultiDirectoriesIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpSetNamesWithMultiDirectoriesIT.java
@@ -25,7 +25,6 @@ import org.apache.camel.Producer;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
import org.apache.camel.test.junit5.TestSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -80,7 +79,7 @@ public class FromFtpSetNamesWithMultiDirectoriesIT extends FtpServerTestSupport
String ftpUrl = "ftp://admin@localhost:{{ftp.server.port}}/incoming/data1/?password=admin&binary=true";
Endpoint endpoint = context.getEndpoint(ftpUrl);
Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo1.jpeg"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo1.jpeg"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo1.jpeg");
Producer producer = endpoint.createProducer();
producer.start();
@@ -90,7 +89,7 @@ public class FromFtpSetNamesWithMultiDirectoriesIT extends FtpServerTestSupport
ftpUrl = "ftp://admin@localhost:{{ftp.server.port}}/incoming/data2/?password=admin&binary=true";
endpoint = context.getEndpoint(ftpUrl);
exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo2.png"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo2.png"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo2.png");
producer = endpoint.createProducer();
producer.start();
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFileIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFileIT.java
index 98e94fcbd23..f2c11630b56 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFileIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFileIT.java
@@ -24,7 +24,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
import org.apache.camel.test.junit5.TestSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -74,7 +73,7 @@ public class FromFtpToBinaryFileIT extends FtpServerTestSupport {
// test that we can pool and store as a local file
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo.jpeg"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo.jpeg");
Producer producer = endpoint.createProducer();
producer.start();
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFilesIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFilesIT.java
index b2df0b1f8fb..f07f6f6ad62 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFilesIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpToBinaryFilesIT.java
@@ -24,7 +24,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
import org.apache.camel.test.junit5.TestSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -80,7 +79,7 @@ public class FromFtpToBinaryFilesIT extends FtpServerTestSupport {
+ "&delay=2000&recursive=false";
Endpoint endpoint = context.getEndpoint(ftpUrl);
Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo.jpeg"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo.jpeg");
Producer producer = endpoint.createProducer();
producer.start();
@@ -91,7 +90,7 @@ public class FromFtpToBinaryFilesIT extends FtpServerTestSupport {
+ "&delay=2000&recursive=false";
endpoint = context.getEndpoint(ftpUrl);
exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo1.jpeg"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo1.jpeg"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo1.jpeg");
producer = endpoint.createProducer();
producer.start();
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingStepwiseIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingStepwiseIT.java
index d5c6c52cf47..1c43a44e52e 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingStepwiseIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpSimpleConsumeStreamingStepwiseIT.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file.remote.integration;
+import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;
@@ -24,7 +25,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
import org.apache.camel.test.junit5.TestSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -69,7 +69,7 @@ public class FtpSimpleConsumeStreamingStepwiseIT extends FtpServerTestSupport {
// prepares the FTP Server by putting a file on the server
Endpoint endpoint = context.getEndpoint(getFtpUrl());
Exchange exchange = endpoint.createExchange();
- exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo3.jpeg"));
+ exchange.getIn().setBody(new File("src/test/data/ftpbinarytest/logo3.jpeg"));
exchange.getIn().setHeader(Exchange.FILE_NAME, "logo3.jpeg");
Producer producer = endpoint.createProducer();
producer.start();
diff --git a/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java b/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
index e65ec08d125..33bb4be6332 100644
--- a/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
+++ b/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
@@ -123,8 +123,8 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
return org.apache.camel.converter.IOConverter.toWriter((java.io.File) value, exchange);
}
} else if (to == java.io.File.class) {
- if (value instanceof java.lang.String) {
- return org.apache.camel.converter.IOConverter.toFile((java.lang.String) value);
+ if (value instanceof java.nio.file.Path) {
+ return org.apache.camel.converter.IOConverter.toFile((java.nio.file.Path) value);
}
} else if (to == java.io.InputStream.class) {
if (value instanceof java.util.stream.Stream) {
@@ -142,12 +142,12 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
if (value instanceof java.lang.String) {
return org.apache.camel.converter.IOConverter.toInputStream((java.lang.String) value, exchange);
}
- if (value instanceof java.nio.ByteBuffer) {
- return org.apache.camel.converter.NIOConverter.toInputStream((java.nio.ByteBuffer) value);
- }
if (value instanceof java.lang.StringBuffer) {
return org.apache.camel.converter.IOConverter.toInputStream((java.lang.StringBuffer) value, exchange);
}
+ if (value instanceof java.nio.ByteBuffer) {
+ return org.apache.camel.converter.NIOConverter.toInputStream((java.nio.ByteBuffer) value);
+ }
if (value instanceof java.lang.StringBuilder) {
return org.apache.camel.converter.IOConverter.toInputStream((java.lang.StringBuilder) value, exchange);
}
@@ -560,7 +560,7 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
return this;
}
} else if (to == java.io.File.class) {
- if (from == java.lang.String.class) {
+ if (from == java.nio.file.Path.class) {
return this;
}
} else if (to == java.io.InputStream.class) {
@@ -579,10 +579,10 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
if (from == java.lang.String.class) {
return this;
}
- if (from == java.nio.ByteBuffer.class) {
+ if (from == java.lang.StringBuffer.class) {
return this;
}
- if (from == java.lang.StringBuffer.class) {
+ if (from == java.nio.ByteBuffer.class) {
return this;
}
if (from == java.lang.StringBuilder.class) {
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
index 98a6fd4c1a1..307af5e61bf 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -88,74 +88,69 @@ public final class IOConverter {
}
@Converter(order = 5)
- public static File toFile(String name) {
- return new File(name);
- }
-
- @Converter(order = 6)
public static OutputStream toOutputStream(File file) throws FileNotFoundException {
return IOHelper.buffered(new FileOutputStream(file));
}
- @Converter(order = 7)
+ @Converter(order = 6)
public static BufferedWriter toWriter(File file, Exchange exchange) throws IOException {
FileOutputStream os = new FileOutputStream(file, false);
return IOHelper.toWriter(os, ExchangeHelper.getCharset(exchange));
}
- @Converter(order = 8)
+ @Converter(order = 7)
public static Reader toReader(InputStream in, Exchange exchange) throws IOException {
return IOHelper.buffered(new InputStreamReader(in, ExchangeHelper.getCharset(exchange)));
}
- @Converter(order = 9)
+ @Converter(order = 8)
public static Reader toReader(byte[] data, Exchange exchange) throws IOException {
return toReader(new ByteArrayInputStream(data), exchange);
}
- @Converter(order = 10)
+ @Converter(order = 9)
public static Writer toWriter(OutputStream out, Exchange exchange) throws IOException {
return IOHelper.buffered(new OutputStreamWriter(out, ExchangeHelper.getCharset(exchange)));
}
- @Converter(order = 11)
+ @Converter(order = 10)
public static Reader toReader(String text) {
// no buffering required as the complete string input is already passed
// over as a whole
return new StringReader(text);
}
- @Converter(order = 12)
+ @Converter(order = 11)
public static InputStream toInputStream(String text, Exchange exchange) throws IOException {
return toInputStream(text.getBytes(ExchangeHelper.getCharset(exchange)));
}
- @Converter(order = 13)
+ @Converter(order = 12)
public static InputStream toInputStream(StringBuffer buffer, Exchange exchange) throws IOException {
return toInputStream(buffer.toString(), exchange);
}
- @Converter(order = 14)
+ @Converter(order = 13)
public static InputStream toInputStream(StringBuilder builder, Exchange exchange) throws IOException {
return toInputStream(builder.toString(), exchange);
}
- @Converter(order = 15)
+ @Converter(order = 14)
public static InputStream toInputStream(BufferedReader buffer, Exchange exchange) throws IOException {
return toInputStream(toString(buffer), exchange);
}
- @Converter(order = 16)
+ @Converter(order = 15)
public static String toString(byte[] data, Exchange exchange) throws IOException {
return new String(data, ExchangeHelper.getCharset(exchange));
}
- @Converter(order = 17)
+ @Converter(order = 16)
public static String toString(File file, Exchange exchange) throws IOException {
return toString(toReader(file, exchange));
}
- @Converter(order = 18)
+ @Converter(order = 17)
public static byte[] toByteArray(File file) throws IOException {
InputStream is = toInputStream(file);
try {
@@ -165,13 +160,13 @@ public final class IOConverter {
}
}
- @Converter(order = 19)
+ @Converter(order = 18)
public static byte[] toByteArray(BufferedReader reader, Exchange exchange) throws IOException {
String s = toString(reader);
return toByteArray(s, exchange);
}
- @Converter(order = 20)
+ @Converter(order = 19)
public static String toString(URL url, Exchange exchange) throws IOException {
InputStream is = toInputStream(url);
try {
@@ -181,39 +176,39 @@ public final class IOConverter {
}
}
- @Converter(order = 21)
+ @Converter(order = 20)
public static String toString(BufferedReader reader) throws IOException {
return IOHelper.toString(reader);
}
- @Converter(order = 22)
+ @Converter(order = 21)
public static String toString(Reader reader) throws IOException {
return IOHelper.toString(reader);
}
- @Converter(order = 23)
+ @Converter(order = 22)
public static byte[] toByteArray(Reader reader, Exchange exchange) throws IOException {
return toByteArray(IOHelper.buffered(reader), exchange);
}
- @Converter(order = 24)
+ @Converter(order = 23)
public static byte[] toByteArray(String value, Exchange exchange) throws IOException {
return value.getBytes(ExchangeHelper.getCharset(exchange));
}
- @Converter(order = 25)
+ @Converter(order = 24)
public static String toString(InputStream in, Exchange exchange) throws IOException {
return toString(toReader(in, exchange));
}
- @Converter(order = 26)
+ @Converter(order = 25)
public static InputStream toInputStream(byte[] data) {
// no buffering required as the complete byte input is already passed
// over as a whole
return new ByteArrayInputStream(data);
}
- @Converter(order = 27)
+ @Converter(order = 26)
public static ObjectOutput toObjectOutput(OutputStream stream) throws IOException {
if (stream instanceof ObjectOutput) {
return (ObjectOutput) stream;
@@ -222,7 +217,7 @@ public final class IOConverter {
}
}
- @Converter(order = 28)
+ @Converter(order = 27)
public static ObjectInput toObjectInput(final InputStream stream, final Exchange exchange) throws IOException {
if (stream instanceof ObjectInput) {
return (ObjectInput) stream;
@@ -249,7 +244,7 @@ public final class IOConverter {
}
}
- @Converter(order = 29)
+ @Converter(order = 28)
public static byte[] toBytes(InputStream stream) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(IOHelper.buffered(stream), bos);
@@ -259,36 +254,36 @@ public final class IOConverter {
return bos.toByteArray();
}
- @Converter(order = 30)
+ @Converter(order = 29)
public static byte[] toByteArray(ByteArrayOutputStream os) {
return os.toByteArray();
}
- @Converter(order = 31)
+ @Converter(order = 30)
public static ByteBuffer covertToByteBuffer(InputStream is) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOHelper.copyAndCloseInput(is, os);
return ByteBuffer.wrap(os.toByteArray());
}
- @Converter(order = 32)
+ @Converter(order = 31)
public static String toString(ByteArrayOutputStream os, Exchange exchange) throws IOException {
return os.toString(ExchangeHelper.getCharset(exchange));
}
- @Converter(order = 33)
+ @Converter(order = 32)
public static InputStream toInputStream(ByteArrayOutputStream os) {
// no buffering required as the complete byte array input is already
// passed over as a whole
return new ByteArrayInputStream(os.toByteArray());
}
- @Converter(order = 34)
+ @Converter(order = 33)
public static Properties toProperties(File file) throws IOException {
return toProperties(new FileInputStream(file));
}
- @Converter(order = 35)
+ @Converter(order = 34)
public static Properties toProperties(InputStream is) throws IOException {
Properties prop = new Properties();
try {
@@ -299,7 +294,7 @@ public final class IOConverter {
return prop;
}
- @Converter(order = 36)
+ @Converter(order = 35)
public static Properties toProperties(Reader reader) throws IOException {
Properties prop = new Properties();
try {
@@ -310,9 +305,14 @@ public final class IOConverter {
return prop;
}
- @Converter(order = 37)
+ @Converter(order = 36)
public static Path toPath(File file) {
return file.toPath();
}
+ @Converter(order = 37)
+ public static File toFile(Path path) {
+ return path.toFile();
+ }
+
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java b/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
index 6ebb93b7210..73e912bc595 100644
--- a/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
@@ -156,13 +156,6 @@ public class ConverterTest extends TestSupport {
LOG.debug("From primitive type array we've created the list: {}", resultList);
}
- @Test
- public void testStringToFile() {
- File file = converter.convertTo(File.class, "foo.txt");
- assertNotNull("Should have converted to a file!");
- assertEquals("foo.txt", file.getName(), "file name");
- }
-
@Test
public void testFileToString() throws Exception {
URL resource = getClass().getResource("dummy.txt");
diff --git a/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc b/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
index 4d709ce4a4d..6eb3ccd9633 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
@@ -96,6 +96,10 @@ Removed `lang` attribute for the `<description>` on every EIPs.
The `InOnly` and `InOut` EIPs has been removed.
Instead, use `SetExchangePattern` or `To` where you can specify exchange pattern to use.
+=== Type Converter
+
+The `String` -> `java.io.File` converter has been removed.
+
=== Tracing
The xref:tracer.adoc[Tracer] and xref:backlog-tracer.adoc[Backlog Tracer] no longer includes internal tracing events