pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject [pulsar] branch master updated: Modify CmdProduce to avoid closing resource manually. (#3472)
Date Fri, 08 Feb 2019 05:26:01 GMT
This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e9505a  Modify CmdProduce to avoid closing resource manually. (#3472)
4e9505a is described below

commit 4e9505a512e5e52ac5ae941e503f8854e5030f33
Author: Fangbin Sun <sunfangbin@gmail.com>
AuthorDate: Fri Feb 8 13:25:55 2019 +0800

    Modify CmdProduce to avoid closing resource manually. (#3472)
---
 .../main/java/org/apache/pulsar/client/cli/CmdProduce.java    | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java
b/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java
index eb8fe96..c1eba86 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java
@@ -24,8 +24,8 @@ import com.beust.jcommander.Parameters;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.RateLimiter;
 
-import java.io.File;
-import java.io.FileInputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -97,13 +97,8 @@ public class CmdProduce {
 
         try {
             for (String filename : messageFileNames) {
-                File f = new File(filename);
-                FileInputStream fis = new FileInputStream(f);
-                byte[] fileBytes = new byte[(int) f.length()];
-                fis.read(fileBytes);
+                byte[] fileBytes = Files.readAllBytes(Paths.get(filename));
                 messageBodies.add(fileBytes);
-                fis.close();
-
             }
         } catch (Exception e) {
             LOG.error(e.getMessage(), e);


Mime
View raw message