ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [09/47] incubator-ignite git commit: # ignite-117 : md5Calculation was moved at GridUtils
Date Thu, 29 Jan 2015 13:51:03 GMT
# ignite-117 : md5Calculation was moved at GridUtils


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

Branch: refs/heads/ignite-113
Commit: 0632bb3b537e24571efc3be8a9ba5b01d3557069
Parents: 3f4c416
Author: Artem SHutak <ashutak@gridgain.com>
Authored: Tue Jan 27 21:38:53 2015 +0300
Committer: Artem SHutak <ashutak@gridgain.com>
Committed: Tue Jan 27 21:38:53 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/util/GridUtils.java  | 34 ++++++++++++++++
 .../shmem/GridIpcSharedMemoryNativeLoader.java  | 38 +-----------------
 .../ignite/internal/util/GridUtilsSelfTest.java | 41 +++++++++++++-------
 ...GridIpcSharedMemoryNativeLoaderSelfTest.java |  8 ----
 4 files changed, 62 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0632bb3b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
index 5279b59..046422a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUtils.java
@@ -9097,4 +9097,38 @@ public abstract class GridUtils {
 
         return list;
     }
+
+    public static byte[] calculateMD5Digest(InputStream input) throws NoSuchAlgorithmException,
IOException {
+        MessageDigest md = MessageDigest.getInstance("MD5");
+        InputStream fis = new BufferedInputStream(input);
+        byte[] dataBytes = new byte[1024];
+
+        int nread;
+        while ((nread = fis.read(dataBytes)) != -1) {
+            md.update(dataBytes, 0, nread);
+        }
+
+        byte[] md5Bytes = md.digest();
+
+        //convert the byte to hex format
+        StringBuilder sb = new StringBuilder("");
+        for (byte md5Byte : md5Bytes) {
+            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
+        }
+
+        return md5Bytes;
+    }
+
+    public static String calculateMD5(InputStream input) throws NoSuchAlgorithmException,
IOException {
+        byte[] md5Bytes = calculateMD5Digest(input);
+
+        //convert the byte to hex format
+        StringBuilder sb = new StringBuilder();
+        for (byte md5Byte : md5Bytes) {
+            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
+        }
+
+        return sb.toString();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0632bb3b/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 243a099..35c4754 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
@@ -24,7 +24,6 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import java.io.*;
 import java.net.URL;
 import java.nio.channels.FileLock;
-import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -250,44 +249,11 @@ public class GridIpcSharedMemoryNativeLoader {
         try (InputStream targetIS = new FileInputStream(target);
              InputStream srcIS = src.openStream()){
 
-            String targetMD5 = calculateMD5(targetIS);
-            String srcMD5 = calculateMD5(srcIS);
+            String targetMD5 = U.calculateMD5(targetIS);
+            String srcMD5 = U.calculateMD5(srcIS);
 
             return targetMD5.equals(srcMD5);
         }
     }
 
-    static byte[] calculateMD5Digest(InputStream input) throws NoSuchAlgorithmException,
IOException {
-        MessageDigest md = MessageDigest.getInstance("MD5");
-        InputStream fis = new BufferedInputStream(input);
-        byte[] dataBytes = new byte[1024];
-
-        int nread;
-        while ((nread = fis.read(dataBytes)) != -1) {
-            md.update(dataBytes, 0, nread);
-        }
-
-        byte[] md5Bytes = md.digest();
-
-        //convert the byte to hex format
-        StringBuilder sb = new StringBuilder("");
-        for (byte md5Byte : md5Bytes) {
-            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
-        }
-
-        return md5Bytes;
-    }
-
-    static String calculateMD5(InputStream input) throws NoSuchAlgorithmException, IOException
{
-        byte[] md5Bytes = calculateMD5Digest(input);
-
-        //convert the byte to hex format
-        StringBuilder sb = new StringBuilder();
-        for (byte md5Byte : md5Bytes) {
-            sb.append(Integer.toString((md5Byte & 0xff) + 0x100, 16).substring(1));
-        }
-
-        return sb.toString();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0632bb3b/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java
index 7996071..3848b7f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java
@@ -17,26 +17,30 @@
 
 package org.apache.ignite.internal.util;
 
-import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
-import org.apache.ignite.compute.*;
-import org.apache.ignite.internal.util.lang.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.testframework.*;
-import org.apache.ignite.testframework.http.*;
-import org.apache.ignite.testframework.junits.*;
-import org.apache.ignite.testframework.junits.common.*;
-import org.jetbrains.annotations.*;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cluster.ClusterGroup;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.internal.util.lang.GridPeerDeployAware;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.http.GridEmbeddedHttpServer;
+import org.apache.ignite.testframework.junits.GridTestKernalContext;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.jetbrains.annotations.Nullable;
 
 import java.io.*;
 import java.lang.annotation.*;
-import java.math.*;
-import java.net.*;
-import java.nio.*;
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.nio.ByteBuffer;
 import java.util.*;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertArrayEquals;
 
 /**
  * Grid utils tests.
@@ -690,6 +694,13 @@ public class GridUtilsSelfTest extends GridCommonAbstractTest {
         assertTrue(ips.get(ips.size() - 1).isUnresolved());
     }
 
+
+    public void testMD5Calculation() throws Exception {
+        String md5 = GridUtils.calculateMD5(new ByteArrayInputStream("Corrupted information.".getBytes()));
+
+        assertEquals("d7dbe555be2eee7fa658299850169fa1", md5);
+    }
+
     /**
      * Test enum.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0632bb3b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
index 2d082c2..c15748a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/GridIpcSharedMemoryNativeLoaderSelfTest.java
@@ -4,7 +4,6 @@ import junit.framework.TestCase;
 import org.apache.ignite.internal.util.GridJavaProcess;
 
 import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Collections;
@@ -31,12 +30,5 @@ public class GridIpcSharedMemoryNativeLoaderSelfTest extends TestCase {
         while ((s = errOut.readLine()) != null) {
             System.out.println("ERR>>>>>> " + s);
         }
-
-    }
-
-    public void testMD5Calculation() throws Exception {
-        String md5 = GridIpcSharedMemoryNativeLoader.calculateMD5(new ByteArrayInputStream("Corrupted
information.".getBytes()));
-
-        assertEquals("d7dbe555be2eee7fa658299850169fa1", md5);
     }
 }
\ No newline at end of file


Mime
View raw message