ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [07/47] incubator-ignite git commit: # ignite-117 : small refactoring
Date Thu, 29 Jan 2015 13:51:01 GMT
# ignite-117 : small refactoring


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/cd613db8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cd613db8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cd613db8

Branch: refs/heads/ignite-113
Commit: cd613db8bc16dcdefa495cdd0c23ad9b85061018
Parents: dca51c3
Author: Artem SHutak <ashutak@gridgain.com>
Authored: Tue Jan 27 18:55:34 2015 +0300
Committer: Artem SHutak <ashutak@gridgain.com>
Committed: Tue Jan 27 18:55:34 2015 +0300

----------------------------------------------------------------------
 .../shmem/GridIpcSharedMemoryNativeLoader.java  | 27 +++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cd613db8/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
index 875d7ba..825a235 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoader.java
@@ -247,10 +247,14 @@ public class GridIpcSharedMemoryNativeLoader {
     }
 
     private static boolean haveEqualMD5(File target, URL src) throws NoSuchAlgorithmException,
IOException {
-        String targetMD5 = calculateMD5(new FileInputStream(target));
-        String srcMD5 = calculateMD5(src.openStream());
+        try (InputStream targetIS = new FileInputStream(target);
+             InputStream srcIS = src.openStream()){
 
-        return targetMD5.equals(srcMD5);
+            String targetMD5 = calculateMD5(targetIS);
+            String srcMD5 = calculateMD5(srcIS);
+
+            return targetMD5.equals(srcMD5);
+        }
     }
 
     static byte[] calculateMD5Digest(InputStream input) throws NoSuchAlgorithmException,
IOException {
@@ -258,18 +262,17 @@ public class GridIpcSharedMemoryNativeLoader {
         InputStream fis = new BufferedInputStream(input);
         byte[] dataBytes = new byte[1024];
 
-        int nread = 0;
-
+        int nread;
         while ((nread = fis.read(dataBytes)) != -1) {
             md.update(dataBytes, 0, nread);
-        };
+        }
 
         byte[] md5Bytes = md.digest();
 
         //convert the byte to hex format
-        StringBuffer sb = new StringBuffer("");
-        for (int i = 0; i < md5Bytes.length; i++) {
-            sb.append(Integer.toString((md5Bytes[i] & 0xff) + 0x100, 16).substring(1));
+        StringBuilder sb = new StringBuilder("");
+        for (byte md5Byte : md5Bytes) {
+            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
         }
 
         System.out.println("Digest(in hex format):: " + sb.toString());
@@ -281,9 +284,9 @@ public class GridIpcSharedMemoryNativeLoader {
         byte[] md5Bytes = calculateMD5Digest(input);
 
         //convert the byte to hex format
-        StringBuffer sb = new StringBuffer("");
-        for (int i = 0; i < md5Bytes.length; i++) {
-            sb.append(Integer.toString((md5Bytes[i] & 0xff) + 0x100, 16).substring(1));
+        StringBuilder sb = new StringBuilder();
+        for (byte md5Byte : md5Bytes) {
+            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
         }
 
         return sb.toString();


Mime
View raw message