ikrs.httpd
Class ETag

java.lang.Object
  extended by ikrs.httpd.ETag

public class ETag
extends java.lang.Object

The ETag (entity tag) is sort of a resource hash. It is built of the resource's name, the resource's size (if available) and the resource's date of last modification; if the modification date is unknown the current time stamp is used, so each time it is called a new hash is generated (the resource might have changed in between). For details see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html


Method Summary
static ETag create(Resource resource, java.net.URI relativeURI)
          Create a new ETag from the given credentials.
 java.lang.String createHeaderValue()
          This method creates a fully qualified ETag HTTP header value.
 java.lang.String createHexHash()
          This method creates the hexadecimal representation of the hashed resource information.
 byte[] createRawHash()
          This method creates the raw hash bytes from the passed resource information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createRawHash

public byte[] createRawHash()
                     throws java.io.IOException,
                            java.security.NoSuchAlgorithmException
This method creates the raw hash bytes from the passed resource information. The returned byte array contains 16 bytes of an MD5 sum.

Returns:
The MD5 hash in a 16-byte-array.
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException

createHexHash

public java.lang.String createHexHash()
                               throws java.io.IOException,
                                      java.security.NoSuchAlgorithmException
This method creates the hexadecimal representation of the hashed resource information. The returned string is never null.

Returns:
A string in hex representation containing the bytes of the MD5 hash for the passed resource information.
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException

createHeaderValue

public java.lang.String createHeaderValue()
                                   throws java.io.IOException,
                                          java.security.NoSuchAlgorithmException
This method creates a fully qualified ETag HTTP header value. The returned string can be directly used for the 'ETag' response header. Note that this ETag implementation only creates weak (!) hashes, so the return string always begins with "W/".

Returns:
A fully qualified ETag value for the response headers.
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException

create

public static ETag create(Resource resource,
                          java.net.URI relativeURI)
                   throws java.lang.NullPointerException
Create a new ETag from the given credentials.

Parameters:
resource - The resource to use (must not be null).
relativeURI - The resource's request URI (relative; may be null).
Throws:
java.lang.NullPointerException - If the passed resource is null.