Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
8da0f5a4
Commit
8da0f5a4
authored
14 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
LMS-1888 new method for calculating checksum also for byte arrays
SVN: 18843
parent
c3257715
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/source/java/ch/systemsx/cisd/common/utilities/MD5ChecksumCalculator.java
+22
-9
22 additions, 9 deletions
...systemsx/cisd/common/utilities/MD5ChecksumCalculator.java
with
22 additions
and
9 deletions
common/source/java/ch/systemsx/cisd/common/utilities/MD5ChecksumCalculator.java
+
22
−
9
View file @
8da0f5a4
...
...
@@ -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
c
alculat
e
(
inputStream
,
4096
);
return
doC
alculat
ion
(
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment