gnodet-bot commented on code in PR #30472:
URL: https://github.com/apache/camel/pull/30472#discussion_r4639321914
##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformer.java:
##########
@@ -28,23 +31,25 @@
/**
* Generic binary data type uses Camel message body converter mechanism to
convert content to byte array representation.
- * A stream cache body is binary already and can be read again, so it is kept
as it is: a large body, such as an object
- * read from a bucket, is not read into memory. Any other stream is read into
a byte array, as it may be read only once.
+ * A stream cache or a file body is binary already and can be read again, so
it is kept as it is: a large body, such as
+ * an object read from a bucket or a file to upload, is not read into memory.
Any other stream is read into a byte
+ * array, as it may be read only once.
*/
@DataTypeTransformer(name = "application-octet-stream")
@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE, Carrier.NULL },
description = "A body Camel can convert
to a byte array: a number fails, and a null"
+ " body stays null"),
- transformerOut = @BodyType(value = { Carrier.BYTES, Carrier.STREAM,
Carrier.NULL },
- description = "A stream cache body is
kept as it is and a null body stays null;"
- + " any other body becomes
a byte array"))
+ transformerOut = @BodyType(value = { Carrier.BYTES, Carrier.STREAM,
Carrier.FILE, Carrier.NULL },
+ description = "A stream cache or a file
body is kept as it is and a null body"
+ + " stays null; any other
body becomes a byte array"))
public class ByteArrayDataTypeTransformer extends Transformer {
private static final Transformer DELEGATE = new
TypeConverterTransformer(byte[].class);
@Override
public void transform(Message message, DataType from, DataType to) throws
Exception {
- if (!(message.getBody() instanceof StreamCache)) {
+ Object body = message.getBody();
+ if (!(body instanceof StreamCache || body instanceof File || body
instanceof WrappedFile)) {
Review Comment:
**Low:** `Carrier.FILE` is documented as including `java.nio.file.Path`
alongside `java.io.File` and `WrappedFile` (see `BodyType.Carrier`: *"A file:
the GenericFile of the file consumers, a java.io.File or a Path."*).
`BodyFacts.java` also groups `Path` with `File` and `WrappedFile` in its
payload check. Missing `Path` here means a `Path` body — though none appears in
production today — would be read into memory by the delegate instead of being
preserved.
```suggestion
if (!(body instanceof StreamCache || body instanceof File || body
instanceof WrappedFile || body instanceof java.nio.file.Path)) {
```
(Or add `import java.nio.file.Path;` at the top and use the short name.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]