public class MacOutputStream
extends com.helger.commons.io.stream.WrappedOutputStream
To complete the Mac computation, call one of the doFinal methods
on the associated message digest after your calls to one of this digest
output stream's write methods.
It is possible to turn this stream on or off (see on). When it is on, a call to one of the write methods results in an
update on the message digest. But when it is off, the message digest is not
updated. The default is for the stream to be on.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_ON |
out| Constructor and Description |
|---|
MacOutputStream(OutputStream aOS,
Mac aMac)
Creates a Mac output stream, using the specified output stream and Mac.
|
| Modifier and Type | Method and Description |
|---|---|
Mac |
getMac()
Returns the Mac associated with this stream.
|
boolean |
isOn() |
void |
setMac(Mac aMac)
Associates the specified Mac with this stream.
|
void |
setOn(boolean bOn)
Turns the function on or off.
|
String |
toString() |
void |
write(byte[] aBuf,
int nOfs,
int nLen)
Updates the Mac (if the function is on) using the specified subarray, and
in any case writes the subarray to the output stream.
|
void |
write(int b)
Updates the Mac (if the function is on) using the specified byte, and in
any case writes the byte to the output stream.
|
getWrappedOutputStreamclose, flush, writepublic static final boolean DEFAULT_ON
public MacOutputStream(@Nonnull OutputStream aOS, @Nonnull Mac aMac)
aOS - the output 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. May not be
null.getMac()public void write(int b)
throws IOException
on), this method calls
update on the message digest associated with this stream,
passing it the byte b. This method then writes the byte to the
output stream, blocking until the byte is actually written.write in class FilterOutputStreamb - the byte to be used for updating and writing to the output stream.IOException - if an I/O error occurs.Mac.update(byte)public void write(@Nonnull byte[] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen) throws IOException
on), this method calls
update on the Mac associated with this stream, passing it the
subarray specifications. This method then writes the subarray bytes to the
output stream, blocking until the bytes are actually written.write in class com.helger.commons.io.stream.WrappedOutputStreamaBuf - the array containing the subarray to be used for updating and
writing to the output stream.nOfs - the offset into b of the first byte to be updated and
written.nLen - the number of bytes of data to be updated and written from
b, starting at offset off.IOException - if an I/O error occurs.Mac.update(byte[], int, int)public final void setOn(boolean bOn)
write 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 String toString()
toString in class com.helger.commons.io.stream.WrappedOutputStreamCopyright © 2016–2019 Philip Helger. All rights reserved.