public class DigesterRepresentation extends WrapperRepresentation
Representation.isTransient().
UNKNOWN_SIZE
Constructor and Description |
---|
DigesterRepresentation(Representation wrappedRepresentation)
Constructor.
By default, the instance relies on the Digest.ALGORITHM_MD5
digest algorithm. |
DigesterRepresentation(Representation wrappedRepresentation,
String algorithm)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkDigest()
Check that the digest computed from the representation content and the
digest declared by the representation are the same.
Since this method relies on the computeDigest(String) method,
and since this method reads entirely the representation's stream, user
must take care of the content of the representation in case the latter is
transient. |
boolean |
checkDigest(String algorithm)
Check that the digest computed from the representation content and the
digest declared by the representation are the same.
|
Digest |
computeDigest()
Compute the representation digest according to MD5 algorithm.
If case this algorithm is the same than the one provided at instantiation, the computation operation is made with the current stored computed value and does not require to exhaust entirely the representation's stream. |
Digest |
computeDigest(String algorithm)
Compute the representation digest according to the given algorithm.
Since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient. |
long |
exhaust()
Exhausts the content of the representation by reading it and silently
discarding anything read.
|
ReadableByteChannel |
getChannel()
Returns a channel with the representation's content.
If it is supported by a file, a read-only instance of FileChannel is returned. This method is ensured to return a fresh channel for each invocation unless it is a transient representation, in which case null is returned. |
Digest |
getComputedDigest()
Returns the current computed digest value of the representation.
|
Reader |
getReader()
Returns a characters reader with the representation's content.
|
InputStream |
getStream()
Returns a stream with the representation's content.
|
String |
getText()
Converts the representation to a string value.
|
void |
write(OutputStream outputStream)
Writes the representation to a byte stream.
|
void |
write(WritableByteChannel writableChannel)
Writes the representation to a byte channel.
|
void |
write(Writer writer)
Writes the representation to a characters writer.
|
getAvailableSize, getCharacterSet, getDigest, getDisposition, getEncodings, getExpirationDate, getLanguages, getLocationRef, getMediaType, getModificationDate, getRange, getRegistration, getSize, getTag, getWrappedRepresentation, isAvailable, isSelectable, isTransient, release, setAvailable, setCharacterSet, setDigest, setDisposition, setEncodings, setExpirationDate, setLanguages, setLocationRef, setLocationRef, setMediaType, setModificationDate, setRange, setSize, setTag, setTransient
append, hasKnownSize, isEmpty, setListener
createClientInfo, equals, includes, isCompatible, toString
public DigesterRepresentation(Representation wrappedRepresentation) throws NoSuchAlgorithmException
Digest.ALGORITHM_MD5
digest algorithm.wrappedRepresentation
- The wrapped representation.NoSuchAlgorithmException
public DigesterRepresentation(Representation wrappedRepresentation, String algorithm) throws NoSuchAlgorithmException
wrappedRepresentation
- The wrapped representation.algorithm
- The digest algorithm.NoSuchAlgorithmException
public boolean checkDigest()
computeDigest(String)
method,
and since this method reads entirely the representation's stream, user
must take care of the content of the representation in case the latter is
transient.
WrapperRepresentation.isTransient()
public boolean checkDigest(String algorithm)
computeDigest(String)
method,
and since this method reads entirely the representation's stream, user
must take care of the content of the representation in case the latter is
transient.
WrapperRepresentation.isTransient()
algorithm
- The algorithm used to compute the digest to compare with. See
constant values in Digest
.public Digest computeDigest()
public Digest computeDigest(String algorithm)
WrapperRepresentation.isTransient()
algorithm
- The algorithm used to compute the digest. See constant values
in Digest
.public long exhaust() throws IOException
exhaust
in class WrapperRepresentation
IOException
public ReadableByteChannel getChannel() throws IOException
Representation
getChannel
in class WrapperRepresentation
IOException
public Digest getComputedDigest()
public Reader getReader() throws IOException
Representation
getReader
in class WrapperRepresentation
IOException
public InputStream getStream() throws IOException
DigestInputStream
class, which allows to compute
progressively the digest value.getStream
in class WrapperRepresentation
IOException
public String getText() throws IOException
Representation
getText
in class WrapperRepresentation
IOException
public void write(OutputStream outputStream) throws IOException
OutputStream
after writing to it as this will be handled by
the Restlet connectors automatically.DigestOutputStream
class, which allows to compute progressively
the digest value.write
in class WrapperRepresentation
outputStream
- The output stream.IOException
public void write(WritableByteChannel writableChannel) throws IOException
Representation
write
in class WrapperRepresentation
writableChannel
- A writable byte channel.IOException
public void write(Writer writer) throws IOException
Representation
Writer
after writing to it as this will be handled
by the Restlet connectors automatically.write
in class WrapperRepresentation
writer
- The characters writer.IOException
Copyright © 2005–2017. All rights reserved.