Package edu.wisc.library.ocfl.api.io
Class FixityCheckChannel
- java.lang.Object
-
- edu.wisc.library.ocfl.api.io.FixityCheckChannel
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteChannel,Channel,ReadableByteChannel,WritableByteChannel
public class FixityCheckChannel extends Object implements ByteChannel
A byte channel wrapper that preforms a fixity check on the bytes that pass through an underlying byte channel. After all of the channel's bytes have been read,checkFixity()should be called.
-
-
Constructor Summary
Constructors Constructor Description FixityCheckChannel(ByteChannel delegate, DigestAlgorithm digestAlgorithm, String expectedDigestValue)Constructs a new FixityCheckChannelFixityCheckChannel(ByteChannel delegate, String digestAlgorithm, String expectedDigestValue)Constructs a new FixityCheckChannel
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckFixity()Performs a fixity check and throws an exception if the check fails.voidclose()FixityCheckChannelenableFixityCheck(boolean enabled)By default fixity checking is enabled.StringgetExpectedDigestValue()booleanisOpen()intread(ByteBuffer dst)intwrite(ByteBuffer src)
-
-
-
Constructor Detail
-
FixityCheckChannel
public FixityCheckChannel(ByteChannel delegate, DigestAlgorithm digestAlgorithm, String expectedDigestValue)
Constructs a new FixityCheckChannel- Parameters:
delegate- the channel to wrapdigestAlgorithm- the digest algorithm to useexpectedDigestValue- the expected digest value
-
FixityCheckChannel
public FixityCheckChannel(ByteChannel delegate, String digestAlgorithm, String expectedDigestValue)
Constructs a new FixityCheckChannel- Parameters:
delegate- the channel to wrapdigestAlgorithm- the digest algorithm to useexpectedDigestValue- the expected digest value
-
-
Method Detail
-
checkFixity
public void checkFixity()
Performs a fixity check and throws an exception if the check fails. This should only be called after the entire contents of the stream has been read.If the check is disabled, nothing happens
- Throws:
FixityCheckException- when the actual digest value does not match the expected value
-
getExpectedDigestValue
public String getExpectedDigestValue()
- Returns:
- the expected digest value
-
enableFixityCheck
public FixityCheckChannel enableFixityCheck(boolean enabled)
By default fixity checking is enabled. Use this method to disable it, and prevent needless digest computation- Parameters:
enabled- if fixity should be checked- Returns:
- this stream
-
read
public int read(ByteBuffer dst) throws IOException
- Specified by:
readin interfaceReadableByteChannel- Throws:
IOException
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-