Class ETagUtil.ETag

  • All Implemented Interfaces:
    Serializable
    Enclosing class:
    ETagUtil

    public static final class ETagUtil.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 ("mid-air 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 finger prints, 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
    • Constructor Detail

      • ETag

        public ETag​(String value,
                    boolean weak)
        Creates a new ETag POJO model with the given data.
        Parameters:
        value - Value returned by getValue().
        weak - Value returned by isWeak().
    • 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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 ETagUtil.ETag star()
        Returns:
        An ETag representing the star tag that matches everything.
      • strong

        public static ETagUtil.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

        @Nullable
        public static ETagUtil.ETag valueOfOrNull​(String value)
        Parameters:
        value - Value to parse.
        Returns:
        The value parsed as an ETag, or null when not parseable as an ETag.
      • weak

        public static ETagUtil.ETag weak​(String value)
        Parameters:
        value - Value of the ETag.
        Returns:
        A new ETag with the given value that uses the weak comparison algorithm.