smolnar82 commented on a change in pull request #162: KNOX-2023 - Recording 
KnoxShellTable builder/filter chain and providing rollback/replay capabilities 
using the call history as well as allowing end-users to export JSON without 
data (in this case only the call history will be serialized)
URL: https://github.com/apache/knox/pull/162#discussion_r331741693
 
 

 ##########
 File path: 
gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/CSVKnoxShellTableBuilder.java
 ##########
 @@ -28,24 +28,26 @@
 
   private boolean withHeaders;
 
+  CSVKnoxShellTableBuilder(long id) {
+    super(id);
+  }
+
   public CSVKnoxShellTableBuilder withHeaders() {
     withHeaders = true;
     return this;
   }
 
   public KnoxShellTable url(String url) throws IOException {
     int rowIndex = 0;
-    URLConnection connection;
-    BufferedReader csvReader = null;
     KnoxShellTable table = null;
-    try {
-      URL urlToCsv = new URL(url);
-      connection = urlToCsv.openConnection();
-      csvReader = new BufferedReader(new 
InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
+    URL urlToCsv = new URL(url);
+    URLConnection connection = urlToCsv.openConnection();
+    try (BufferedReader csvReader = new BufferedReader(new 
InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));) {
 
 Review comment:
   `BufferedReader` closes the given `Reader` for you when you invoke `close` 
on it:
   
   ```
   public void close() throws IOException {
       synchronized (lock) {
               if (in == null)
                   return;
               try {
                   in.close();
               } finally {
                   in = null;
                   cb = null;
               }
       }
   }
   ```
   
   On the other hand, I can make this little change as it does not cause any 
harm (` Closing a previously closed stream has no effect.`)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to