This is an automated email from the ASF dual-hosted git repository.

journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new d52a83b  modify FileUtils.readFile2Str (#1535)
d52a83b is described below

commit d52a83bfcf27ac1d226f6644d29fc1909e555b6e
Author: Yelli <[email protected]>
AuthorDate: Sat Dec 21 10:48:40 2019 +0800

    modify FileUtils.readFile2Str (#1535)
---
 .../dolphinscheduler/common/utils/FileUtils.java   | 39 ++++++----------------
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
index 5f23a1e..c84848f 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
@@ -152,7 +152,7 @@ public class FileUtils {
             }
             bufferedReader = new BufferedReader(new StringReader(content));
             bufferedWriter = new BufferedWriter(new FileWriter(distFile));
-            char buf[] = new char[1024];
+            char[] buf = new char[1024];
             int len;
             while ((len = bufferedReader.read(buf)) != -1) {
                 bufferedWriter.write(buf, 0, len);
@@ -320,7 +320,7 @@ public class FileUtils {
             if (file.isDirectory()) {
                 throw new IOException("File '" + file + "' exists but is a 
directory");
             }
-            if (file.canWrite() == false) {
+            if (!file.canWrite()) {
                 throw new IOException("File '" + file + "' cannot be written 
to");
             }
         } else {
@@ -377,41 +377,24 @@ public class FileUtils {
             throw new RuntimeException("parentDir not exist, or is not a 
directory:"+parentDir);
         }
 
-        File[] schemaDirs = file.listFiles(new FileFilter() {
-
-            @Override
-            public boolean accept(File pathname) {
-                if (pathname.isDirectory()) {
-                    return true;
-                }
-                else {
-                    return false;
-                }
-            }
-        });
-
-        return schemaDirs;
+        return file.listFiles(File::isDirectory);
     }
 
     /**
      * Get Content
      * @param inputStream input stream
      * @return string of input stream
-     * @throws IOException errors
      */
-    public static String readFile2Str(InputStream inputStream) throws 
IOException{
-        String all_content=null;
+    public static String readFile2Str(InputStream inputStream) {
+
         try {
-            all_content = new String();
-            InputStream ins = inputStream;
-            ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
-            byte[] str_b = new byte[1024];
-            int i = -1;
-            while ((i=ins.read(str_b)) > 0) {
-                outputstream.write(str_b,0,i);
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int length;
+            while ((length= inputStream.read(buffer)) != -1) {
+                output.write(buffer,0,length);
             }
-            all_content = outputstream.toString();
-            return all_content;
+            return output.toString();
         } catch (Exception e) {
             logger.error(e.getMessage(),e);
             throw new RuntimeException(e);

Reply via email to