turcsanyip commented on code in PR #7588:
URL: https://github.com/apache/nifi/pull/7588#discussion_r1301140166
##########
nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/flow/resource/hadoop/HDFSExternalResourceProvider.java:
##########
@@ -140,13 +146,16 @@ public InputStream fetchExternalResource(final
ExternalResourceDescriptor descri
final HdfsResources hdfsResources = getHdfsResources();
try {
- return
hdfsResources.getUserGroupInformation().doAs((PrivilegedExceptionAction<FSDataInputStream>)
() -> {
- if (!hdfsResources.getFileSystem().exists(path)) {
- throw new IOException("Cannot find file in HDFS at
location " + location);
- }
-
- return hdfsResources.getFileSystem().open(path,
BUFFER_SIZE_DEFAULT);
- });
+ final FSDataInputStream fsDataInputStream =
+
hdfsResources.getUserGroupInformation().doAs((PrivilegedExceptionAction<FSDataInputStream>)
() -> {
+ if (!hdfsResources.getFileSystem().exists(path)) {
+ throw new IOException("Cannot find file in HDFS at
location " + location);
+ }
+
+ return hdfsResources.getFileSystem().open(path,
BUFFER_SIZE_DEFAULT);
+ });
+ // The acquired InputStream is used by the client and cannot be
closed here. The decorator is responsible for that.
Review Comment:
I also think some additional documentation would not be useless.
Regarding the "why": the point is that the `FileSystem` cannot be closed
here so I would modify the comment:
```suggestion
// The acquired InputStream is used by the client and for this
reason the FileSystem cannot be closed here. The decorator is responsible for
that.
```
Regarding the "how": I would highlight which method behaves differently and
does not simply delegates the call to the decorated object. It could be added
in the javadoc of `HDFSResourceInputStream` or simply here.
I agree that the benefits of patterns is sharing the intention, however it
is useful to highlight the additional behaviour in case of a decorator.
--
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]