Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2016-03-20 11:05:14 +0000
committerPascal Rapicault2016-04-21 03:24:22 +0000
commit5b2f061cd8ecf96a37783657e7ee7a0110c9d26d (patch)
tree01b67b9966c0537612720540982be69f4632b408 /bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox
parentb1b3edccf441e5b5edf90e4c9cc08acf6d197f92 (diff)
downloadrt.equinox.p2-5b2f061cd8ecf96a37783657e7ee7a0110c9d26d.tar.gz
rt.equinox.p2-5b2f061cd8ecf96a37783657e7ee7a0110c9d26d.tar.xz
rt.equinox.p2-5b2f061cd8ecf96a37783657e7ee7a0110c9d26d.zip
Bug 490028 - Extract MD5 checksum calculation into a separate class
MD5 checksum is calculated in (almost) the same way in two places: org.eclipse.equinox.p2.internal.repository.tools.RepositoryUtilities and org.eclipse.equinox.spi.p2.publisher.PublisherHelper. The latter uses 4K byte buffer instead of byte-by-byte update which makes MD5 calculation for a 300k jar file 5x faster, see bug #405716 for more details. Due to the duplication, this has been fixed in PublisherHelper only but not in RepositoryUtilities. Eliminate code duplication by extracting MD5 checksum calculation into a separate class, ChecksumProducer. To make it consimable by org.eclipse.equinox.p2.publisher and org.eclipse.equinox.p2.repository.tools bundles but not exposing too much internals, move it to the x-friend'ed org.eclipse.equinox.internal.p2.repository.helpers package of org.eclipse.equinox.p2.repository bundle. Change-Id: Ic8b45a47700f35af1fb69f534dec7b32a2f7714a Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryUtilities.java44
1 files changed, 5 insertions, 39 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryUtilities.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryUtilities.java
index 11e3e32c6..01d89a2ca 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryUtilities.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryUtilities.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
+ * Copyright (c) 2009, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,51 +7,17 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Mykola Nikishov - extract MD5 checksum calculation
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools;
-import java.io.*;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+import java.io.File;
+import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer;
public class RepositoryUtilities {
public static String computeMD5(File file) {
- if (file == null || file.isDirectory() || !file.exists())
- return null;
- MessageDigest md5Checker;
- try {
- md5Checker = MessageDigest.getInstance("MD5"); //$NON-NLS-1$
- } catch (NoSuchAlgorithmException e) {
- return null;
- }
- InputStream fis = null;
- try {
- fis = new BufferedInputStream(new FileInputStream(file));
- int read = -1;
- while ((read = fis.read()) != -1) {
- md5Checker.update((byte) read);
- }
- byte[] digest = md5Checker.digest();
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < digest.length; i++) {
- if ((digest[i] & 0xFF) < 0x10)
- buf.append('0');
- buf.append(Integer.toHexString(digest[i] & 0xFF));
- }
- return buf.toString();
- } catch (FileNotFoundException e) {
- return null;
- } catch (IOException e) {
- return null;
- } finally {
- if (fis != null)
- try {
- fis.close();
- } catch (IOException e) {
- // ignore
- }
- }
+ return ChecksumProducer.computeMD5(file);
}
}

Back to the top