Interface ReadableResource

All Superinterfaces:
AbstractResource
All Known Subinterfaces:
CloseableResource, ReadableButNotWritableResource, Resource, WritableButNotReadableResource
All Known Implementing Classes:
ClasspathResource, DataResource, DelegatingMultipartResource, DelegatingReadableResource, DelegatingResource, EmptyResource, ErrorResource, FileDescriptorResource, FileResource, IntegrityValidatingDelegatingResource, MarkdownResource, MemoryResource, MultibaseResource, NullResource, OkHttpResource, ReadableButNotWritableDelegatingResource, RegexMultipartResource, ReplacingResource, StringResource, TestResource, UrlResource, WritableButNotReadableDelegatingResource

public interface ReadableResource extends AbstractResource
  • Method Details

    • byteSource

      com.google.common.io.ByteSource byteSource()
    • charSource

      default com.google.common.io.CharSource charSource()
    • changeToken

      default ChangeToken changeToken()
      ChangeToken of this resource's content. Implementations may e.g. be based on:

      Intended to be used for change detection, like this:

      1. Obtain the ChangeToken of a Resource using this method.
      2. Store it somewhere; either in-memory as a Java object, or possibly externally in its ChangeToken.toString() or ChangeToken.toBytes() form.
      3. Later, to check if the Resource at this same (!) AbstractResource.uri() has changed, get another ChangeToken using this method
      4. To compare the original and current one, use ChangeToken.isDifferent(ChangeToken), or isDifferent(String) or isDifferent(ByteSeq).

      Implementations may be based on byteSource() (typically irrelevant of encoding and thus charSource()), and possibly metadata not available via the Resource API. It may it ignore AbstractResource.uri() and AbstractResource.mediaType(). Ergo, 2 resources with the same bytes content may have the same ChangeToken, even if they have different URIs, but this should not be relied upon. ChangeTokens should only be interchange if and only if they are instances of the same (Java implementation of) Resource type - separate implementations will create different change tokens, which will always be considered different.

      ChangeToken calculation could be an expensive operation. For example, obtaining a checksum of a large file (if that's how a resource implements this method) would require reading that entire file.

      Resources may cache or may not cache ChangeTokens, or be cached for a certain time. This is entirely dependent on the implementation.

      The default implementations currently returns a Multibase RFC-4648 Base64url encoded SHA2-512 CHF MAC. This default may be changed at any time, without notice. At least some implementations of this interface may well use entirely different solutions.

      Returns:
      Change Token, never null.
    • isDifferent

      default boolean isDifferent(String previousToString)
      Like ChangeToken.isDifferent(ChangeToken), but given a String instead of an object.
      Parameters:
      previousToString - The output of calling ChangeToken.toString() on a ChangeToken previously obtained from changeToken() for this Resource.
      Returns:
      see ChangeToken.isDifferent(ChangeToken)
    • isDifferent

      default boolean isDifferent(ByteSeq previousBytes)