Package de.xima.fc.common.etag
Class ETag
- java.lang.Object
-
- de.xima.fc.common.etag.ETag
-
- All Implemented Interfaces:
Serializable
public final class ETag extends Object implements Serializable
POJO models for an ETag that can be exchanged via HTTP requests for cache control etc.The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource. It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content was not changed. Additionally, ETag help to prevent simultaneous updates of a resource from overwriting each other ("midair collisions"). If the resource at a given URL changes, a new ETag value must be generated. A comparison of them can determine whether two representations of a resource are the same. ETag are therefore similar to fingerprints, and might also be used for tracking purposes by some servers. They might also be set to persist indefinitely by a tracking server.
- Since:
- 1.0.0
- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
String
getValue()
int
hashCode()
boolean
isStar()
boolean
isWeak()
static ETag
star()
static ETag
strong(String value)
String
toString()
static ETag
valueOfOrNull(String value)
static ETag
weak(String value)
-
-
-
Constructor Detail
-
ETag
public ETag(String value, boolean weak)
Creates a new ETag POJO model with the given data.- Parameters:
value
- Value returned bygetValue()
.weak
- Value returned byisWeak()
.
-
-
Method Detail
-
getValue
public String getValue()
- Returns:
- Entity tag that uniquely represents the requested resource. It is a string of ASCII characters placed between double quotes, like "675af34563dc-tr34". The method by which ETag values are generated is not specified. Typically, the ETag value is a hash of the content, a hash of the last modification time stamp, or just a revision number. For example, a wiki engine can use a hexadecimal hash of the documentation article content.
-
isStar
public boolean isStar()
- Returns:
- Whether this ETag is a star tag that matches everything.
-
isWeak
public boolean isWeak()
- Returns:
- The
W/
(case-sensitive) indicates that a weak validator is used. Weak ETags are easy to generate, but are far less useful for comparisons. Strong validators are ideal for comparisons but can be very difficult to generate efficiently. Weak ETag values of two representations of the same resources might be semantically equivalent, but not byte-for-byte identical. This means weak ETags prevent caching when byte range requests are used, but strong ETags mean range requests can still be cached.
-
star
public static ETag star()
- Returns:
- An ETag representing the star tag that matches everything.
-
strong
public static ETag strong(String value)
- Parameters:
value
- Value of the ETag.- Returns:
- A new ETag with the given value that does not use the weak comparison algorithm.
-
valueOfOrNull
public static ETag valueOfOrNull(String value)
- Parameters:
value
- Value to parse.- Returns:
- The value parsed as an ETag, or
null
when not parseable as an ETag.
-
-