gnodet-bot commented on code in PR #30918:
URL: https://github.com/apache/camel/pull/30918#discussion_r4716490051
##########
components/camel-parquet-avro/src/main/java/org/apache/camel/dataformat/parquet/avro/ParquetAvroDataFormat.java:
##########
@@ -116,12 +129,36 @@ public void marshal(Exchange exchange, Object graph,
OutputStream stream) throws
.withCompressionCodec(compressionCodecName)
.withWriteMode(OVERWRITE)
.build()) {
- for (Object grapElem : list) {
+ for (Object grapElem : records) {
writer.write(grapElem);
}
}
}
+ /**
+ * The records to write: a List as is, the elements of another Iterable
(such as a Set), of an array, of an Iterator
+ * or of a Stream, or the body itself as a single record. A Path is a
single value, although it is an Iterable of
+ * its names.
+ */
+ private static List<?> toRecords(Object graph) {
+ if (graph instanceof List<?> list) {
+ return list;
+ }
+ List<Object> records = new ArrayList<>();
+ if (graph instanceof Iterable<?> iterable && !(graph instanceof Path))
{
+ iterable.forEach(records::add);
+ } else if (graph instanceof Object[] array) {
+ Collections.addAll(records, array);
+ } else if (graph instanceof Iterator<?> iterator) {
+ iterator.forEachRemaining(records::add);
+ } else if (graph instanceof Stream<?> stream) {
+ stream.forEach(records::add);
Review Comment:
⚠️ **Resource leak: `Stream` not closed**
`Stream` implements `AutoCloseable`. Streams backed by I/O resources (e.g.
`Files.lines()`, JPA/Hibernate streaming queries, `StreamSupport` over a JDBC
`ResultSet`) must be closed after consumption or the underlying resource leaks.
`stream.forEach()` does not close the stream.
Use try-with-resources:
```suggestion
} else if (graph instanceof Stream<?> stream) {
try (stream) {
stream.forEach(records::add);
}
```
--
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]