|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.resource.Variant
org.restlet.resource.Representation
org.restlet.util.WrapperRepresentation
org.restlet.resource.DigestRepresentation
public abstract class DigestRepresentation
Representation capable of computing a digest. It wraps another representation
and allows to get the computed digest of the wrapped entity after reading or
writing operations. The final digest value is guaranteed to be correct only
after the wrapped representation has been entirely exhausted (that is to say
read or written).
This wrapper allows to get the computed digest at the same time the
representation is read or written. It does not need two separate operations
which may require specific attention for transient representations.
Representation.isTransient().
Field Summary |
---|
Fields inherited from class org.restlet.resource.Representation |
---|
UNKNOWN_SIZE |
Constructor Summary | |
---|---|
DigestRepresentation(Representation wrappedRepresentation)
Constructor. By default, the instance relies on the Digest.ALGORITHM_MD5
digest algorithm. |
|
DigestRepresentation(Representation wrappedRepresentation,
java.lang.String algorithm)
Constructor. |
Method Summary | |
---|---|
boolean |
checkDigest()
Check that the digest computed from the wrapped representation content and the digest declared by the wrapped representation are the same. |
boolean |
checkDigest(java.lang.String algorithm)
Check that the digest computed from the representation content and the digest declared by the representation are the same. |
Digest |
computeDigest(java.lang.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. |
java.nio.channels.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. |
java.io.Reader |
getReader()
Returns a characters reader with the representation's content. |
java.io.InputStream |
getStream()
Returns a stream with the representation's content. |
void |
write(java.io.OutputStream outputStream)
Writes the representation to a byte stream. |
void |
write(java.nio.channels.WritableByteChannel writableChannel)
Writes the representation to a byte channel. |
void |
write(java.io.Writer writer)
Writes the representation to a characters writer. |
Methods inherited from class org.restlet.util.WrapperRepresentation |
---|
exhaust, getAvailableSize, getCharacterSet, getDigest, getDownloadName, getEncodings, getExpirationDate, getIdentifier, getLanguages, getMediaType, getModificationDate, getRange, getSize, getTag, getText, getWrappedRepresentation, isAvailable, isDownloadable, isTransient, release, setAvailable, setCharacterSet, setDigest, setDownloadable, setDownloadName, setEncodings, setExpirationDate, setIdentifier, setIdentifier, setLanguages, setMediaType, setModificationDate, setRange, setSize, setTag, setTransient |
Methods inherited from class org.restlet.resource.Representation |
---|
createEmpty |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DigestRepresentation(Representation wrappedRepresentation) throws java.security.NoSuchAlgorithmException
Digest.ALGORITHM_MD5
digest algorithm.
wrappedRepresentation
- The wrapped representation.
java.security.NoSuchAlgorithmException
public DigestRepresentation(Representation wrappedRepresentation, java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
wrappedRepresentation
- The wrapped representation.algorithm
- The digest algorithm
java.security.NoSuchAlgorithmException
Method Detail |
---|
public boolean checkDigest()
checkDigest
in class WrapperRepresentation
public boolean checkDigest(java.lang.String algorithm)
Representation.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.
Representation.isTransient
checkDigest
in class WrapperRepresentation
algorithm
- The algorithm used to compute the digest to compare with. See
constant values in Digest
.
public Digest computeDigest(java.lang.String algorithm)
Representation.isTransient
computeDigest
in class WrapperRepresentation
algorithm
- The algorithm used to compute the digest. See constant values
in Digest
.
public java.nio.channels.ReadableByteChannel getChannel() throws java.io.IOException
Representation
getChannel
in class WrapperRepresentation
java.io.IOException
public Digest getComputedDigest()
public java.io.Reader getReader() throws java.io.IOException
Representation
getReader
in class WrapperRepresentation
java.io.IOException
public java.io.InputStream getStream() throws java.io.IOException
DigestInputStream
class, which allows to compute
progressively the digest value.
getStream
in class WrapperRepresentation
java.io.IOException
public void write(java.io.OutputStream outputStream) throws java.io.IOException
DigestOutputStream
class, which allows to compute progressively
the digest value.
write
in class WrapperRepresentation
outputStream
- The output stream.
java.io.IOException
public void write(java.nio.channels.WritableByteChannel writableChannel) throws java.io.IOException
Representation
write
in class WrapperRepresentation
writableChannel
- A writable byte channel.
java.io.IOException
public void write(java.io.Writer writer) throws java.io.IOException
Representation
write
in class WrapperRepresentation
writer
- The characters writer.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |