public class MacInputStream
extends com.helger.commons.io.stream.WrappedInputStream
To complete the Mac computation, call one of the doFinal methods
on the associated Mac after your calls to one of this Mac input stream's
read methods.
It is possible to turn this stream on or off (see on). When it is on, a call to one of the read methods results in an
update on the Mac. But when it is off, the Mac is not updated. The default is
for the stream to be on.
Note that Mac objects can compute only one digest (see Mac), so that
in order to compute intermediate digests, a caller should retain a handle
onto the Mac object, and clone it for each digest to be computed, leaving the
original digest untouched.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_ON |
in| Constructor and Description |
|---|
MacInputStream(InputStream aIS,
Mac aMac)
Creates a Mac input stream, using the specified input stream and Mac.
|
| Modifier and Type | Method and Description |
|---|---|
Mac |
getMac()
Returns the Mac associated with this stream.
|
boolean |
isOn() |
int |
read()
Reads a byte, and updates the Mac (if the function is on).
|
int |
read(byte[] aBuf,
int nOfs,
int nLen)
Reads into a byte array, and updates the Mac (if the function is on).
|
void |
setMac(Mac aMac)
Associates the specified Mac with this stream.
|
void |
setOn(boolean bOn)
Turns the function on or off.
|
String |
toString() |
available, close, mark, markSupported, read, reset, skippublic static final boolean DEFAULT_ON
public MacInputStream(@Nonnull InputStream aIS, @Nonnull Mac aMac)
aIS - the input stream.aMac - the Mac to associate with this stream.@Nonnull public final Mac getMac()
setMac(Mac)public final void setMac(@Nonnull Mac aMac)
aMac - the Mac to be associated with this stream.getMac()public final void setOn(boolean bOn)
read methods results in an update on the Mac. But when
it is off, the Mac is not updated.bOn - true to turn the function on, false to
turn it off.public final boolean isOn()
true if Mac processing is on, false if it
is offpublic int read()
throws IOException
on), this
method will then call update on the Mac associated with this
stream, passing it the byte read.read in class FilterInputStreamIOException - if an I/O error occurs.Mac.update(byte)public int read(@Nonnull byte[] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen) throws IOException
len bytes from the input stream into
the array b, starting at offset off. This method blocks
until the data is actually read. If the function is on (see
on), this method will then call update on
the Mac associated with this stream, passing it the data.read in class FilterInputStreamaBuf - the array into which the data is read.nOfs - the starting offset into b of where the data should be
placed.nLen - the maximum number of bytes to be read from the input stream into b,
starting at offset off.len if
the end of the stream is reached prior to reading len
bytes. -1 is returned if no bytes were read because the end of the
stream had already been reached when the call was made.IOException - if an I/O error occurs.Mac.update(byte[], int, int)public String toString()
toString in class com.helger.commons.io.stream.WrappedInputStreamCopyright © 2016–2019 Philip Helger. All rights reserved.