Skip to content
Snippets Groups Projects
Commit 8da0f5a4 authored by felmer's avatar felmer
Browse files

LMS-1888 new method for calculating checksum also for byte arrays

SVN: 18843
parent c3257715
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
package ch.systemsx.cisd.common.utilities;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
......@@ -32,10 +33,21 @@ public final class MD5ChecksumCalculator implements IChecksumCalculator
{
public String calculateChecksum(InputStream inputStream) throws IOException
{
return calculate(inputStream, 4096);
return doCalculation(inputStream, 4096);
}
private static String calculate(InputStream inputStream, int bufferSize) throws IOException
private static String calculate(InputStream inputStream, int bufferSize)
{
try
{
return doCalculation(inputStream, bufferSize);
} catch (IOException ex)
{
throw new IllegalStateException("This should not happen: " + ex.getMessage());
}
}
static String doCalculation(InputStream inputStream, int bufferSize) throws IOException
{
byte[] buf = new byte[bufferSize];
MD5InputStream in = new MD5InputStream(inputStream);
......@@ -44,6 +56,13 @@ public final class MD5ChecksumCalculator implements IChecksumCalculator
}
return MD5.asHex(in.hash());
}
/** Calculates a checksum for specified byte array. */
public static String calculate(byte[] bytes)
{
assert bytes != null : "Unspecified byte array.";
return calculate(new ByteArrayInputStream(bytes), bytes.length);
}
/** Calculates a checksum for a given String */
public static String calculate(String value)
......@@ -60,12 +79,6 @@ public final class MD5ChecksumCalculator implements IChecksumCalculator
}
};
try
{
return calculate(inputStream, value.length());
} catch (IOException ex)
{
throw new IllegalStateException("This should not happen: " + ex.getMessage());
}
return calculate(inputStream, value.length());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment