X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.fastlz%2Ftestcases%2Forg%2Fsimantics%2Ffastlz%2FChecksumUtil.java;h=aea3a02963478c4e7f35b36fb82dda70a5c6b377;hb=f8324fc5a564f6eb45af8318471cb7197490f74e;hp=04cdde232bf4192729fec4230408a4d12e84c752;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.fastlz/testcases/org/simantics/fastlz/ChecksumUtil.java b/bundles/org.simantics.fastlz/testcases/org/simantics/fastlz/ChecksumUtil.java index 04cdde232..aea3a0296 100644 --- a/bundles/org.simantics.fastlz/testcases/org/simantics/fastlz/ChecksumUtil.java +++ b/bundles/org.simantics.fastlz/testcases/org/simantics/fastlz/ChecksumUtil.java @@ -1,71 +1,71 @@ -package org.simantics.fastlz; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * @author Tuukka Lehtonen - */ -public final class ChecksumUtil { - - public static byte[] computeSum(byte[] in) { - if (in == null) - throw new IllegalArgumentException("Input cannot be null!"); - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - md.update(in, 0, in.length); - return md.digest(); - } catch (NoSuchAlgorithmException e) { - throw new Error("MD5 digest must be supported by JVM"); - } - } - - public static byte[] computeSum(InputStream in) throws IOException { - if (in == null) - throw new IllegalArgumentException("Input cannot be null!"); - - MessageDigest md; - try { - md = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - throw new Error("MD5 digest must be supported by JVM"); - } - byte[] data = new byte[64 * 1024]; - - while (true) { - int read = in.read(data); - if (read == -1) { - return md.digest(); - } - md.update(data, 0, read); - } - } - - public static byte[] computeSum(File f) throws IOException { - InputStream in = null; - try { - in = new FileInputStream(f); - return computeSum(in); - } finally { - if (in != null) - in.close(); - } - } - - public static byte[] computeSum(URL url) throws IOException { - InputStream in = null; - try { - in = url.openStream(); - return computeSum(in); - } finally { - if (in != null) - in.close(); - } - } - -} +package org.simantics.fastlz; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * @author Tuukka Lehtonen + */ +public final class ChecksumUtil { + + public static byte[] computeSum(byte[] in) { + if (in == null) + throw new IllegalArgumentException("Input cannot be null!"); + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(in, 0, in.length); + return md.digest(); + } catch (NoSuchAlgorithmException e) { + throw new Error("MD5 digest must be supported by JVM"); + } + } + + public static byte[] computeSum(InputStream in) throws IOException { + if (in == null) + throw new IllegalArgumentException("Input cannot be null!"); + + MessageDigest md; + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new Error("MD5 digest must be supported by JVM"); + } + byte[] data = new byte[64 * 1024]; + + while (true) { + int read = in.read(data); + if (read == -1) { + return md.digest(); + } + md.update(data, 0, read); + } + } + + public static byte[] computeSum(File f) throws IOException { + InputStream in = null; + try { + in = new FileInputStream(f); + return computeSum(in); + } finally { + if (in != null) + in.close(); + } + } + + public static byte[] computeSum(URL url) throws IOException { + InputStream in = null; + try { + in = url.openStream(); + return computeSum(in); + } finally { + if (in != null) + in.close(); + } + } + +}