Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update applyDigestToBlobs to return a FixityResult object with the ch…
…ecksum and size
- Loading branch information
Showing
5 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
fcrepo-kernel/src/main/java/org/fcrepo/utils/FixityInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.fcrepo.utils; | ||
|
||
import org.apache.commons.io.input.CountingInputStream; | ||
import org.apache.commons.io.input.ProxyInputStream; | ||
|
||
import java.io.FilterInputStream; | ||
import java.io.InputStream; | ||
import java.security.DigestInputStream; | ||
import java.security.MessageDigest; | ||
|
||
public class FixityInputStream extends ProxyInputStream { | ||
|
||
/** | ||
* Creates a <code>FilterInputStream</code> | ||
* by assigning the argument <code>in</code> | ||
* to the field <code>this.in</code> so as | ||
* to remember it for later use. | ||
* | ||
* @param in the underlying input stream, or <code>null</code> if | ||
* this instance is to be created without an underlying stream. | ||
*/ | ||
public FixityInputStream(InputStream in, MessageDigest digest) { | ||
super(new CountingInputStream(new DigestInputStream(in, digest))); | ||
} | ||
|
||
public long getByteCount() { | ||
return ((CountingInputStream)in).getByteCount(); | ||
} | ||
|
||
public MessageDigest getMessageDigest() { | ||
return ((DigestInputStream)in).getMessageDigest(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
fcrepo-kernel/src/main/java/org/fcrepo/utils/FixityResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.fcrepo.utils; | ||
|
||
public class FixityResult { | ||
public long computedSize; | ||
|
||
public String computedChecksum; | ||
|
||
public boolean equals(Object obj) { | ||
|
||
boolean result = false; | ||
if (obj instanceof FixityResult) { | ||
FixityResult that = (FixityResult) obj; | ||
result = this.computedSize == that.computedSize && this.computedChecksum.equals(that.computedChecksum); | ||
|
||
} | ||
|
||
return result; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
fcrepo-kernel/src/test/java/org/fcrepo/utils/FixityInputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.fcrepo.utils; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
public class FixityInputStreamTest { | ||
|
||
@Test | ||
public void SimpleFixityInputStreamTest() throws NoSuchAlgorithmException { | ||
FixityInputStream is = new FixityInputStream(new ByteArrayInputStream("0123456789".getBytes()), MessageDigest.getInstance("SHA-1")); | ||
|
||
try { | ||
while(is.read() != -1); | ||
} catch (IOException e) { | ||
|
||
} | ||
|
||
assertEquals(10, is.getByteCount()); | ||
} | ||
} |