dan-s1 commented on code in PR #9758:
URL: https://github.com/apache/nifi/pull/9758#discussion_r1977592809


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java:
##########
@@ -1070,4 +1070,14 @@ private Response performRequest(final String method, 
final String endpoint, fina
 
         return client.performRequest(request);
     }
+
+    private String readContentAsUtf8String(HttpEntity entity) throws 
UnsupportedOperationException, IOException {
+        return this.readContentAsString(entity, StandardCharsets.UTF_8);
+    }
+
+    private String readContentAsString(HttpEntity entity, Charset charset) 
throws UnsupportedOperationException, IOException {
+        try (InputStream responseStream = entity.getContent()) {
+            return IOUtils.toString(responseStream, charset);
+        }
+    }

Review Comment:
   No need to use `IOUtils`, you can use a `String` constructor and then drop 
the need to include in the method signatures `UnsupportedOperationException`. I 
also believe you can them remove the import for `IOUtils`.
   ```suggestion
       private String readContentAsUtf8String(HttpEntity entity) throws  
IOException {
           return this.readContentAsString(entity, StandardCharsets.UTF_8);
       }
   
       private String readContentAsString(HttpEntity entity, Charset charset) 
throws  IOException {
           try (InputStream responseStream = entity.getContent()) {
               return new String(responseStream.readAllBytes(), charset);
           }
       }
   ```



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java:
##########
@@ -597,10 +597,8 @@ private Map<String, Object> parseResponse(final Response 
response) {
 
         try {
             if (code >= 200 && code < 300) {
-                final InputStream inputStream = 
response.getEntity().getContent();
-                final byte[] result = IOUtils.toByteArray(inputStream);
-                inputStream.close();
-                return mapper.readValue(new String(result, responseCharset), 
Map.class);
+                String body = this.readContentAsString(response.getEntity(), 
this.responseCharset);

Review Comment:
   ```suggestion
                   final String body = 
this.readContentAsString(response.getEntity(), this.responseCharset);
   ```



-- 
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]

Reply via email to