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
-
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.io.ByteSource
default ChangeToken
ChangeToken
of this resource's content.default com.google.common.io.CharSource
default boolean
isDifferent
(ByteSeq previousBytes) default boolean
isDifferent
(String previousToString) LikeChangeToken.isDifferent(ChangeToken)
, but given a String instead of an object.Methods inherited from interface dev.enola.common.io.resource.AbstractResource
mediaType, uri
-
Method Details
-
byteSource
com.google.common.io.ByteSource byteSource() -
charSource
default com.google.common.io.CharSource charSource() -
changeToken
ChangeToken
of this resource's content. Implementations may e.g. be based on:- mtime Timestamp of a File or Directory
- HTTP Last-Modified
- HTTP Etag
- Merkle tree, e.g. of a Directory
- Hash (checksum) of content
- Git SHA revision
- IPFS URL CID
- ...
Intended to be used for change detection, like this:
- Obtain the ChangeToken of a Resource using this method.
- Store it somewhere; either in-memory as a Java object, or possibly externally in its
ChangeToken.toString()
orChangeToken.toBytes()
form. - Later, to check if the Resource at this same (!)
AbstractResource.uri()
has changed, get another ChangeToken using this method - To compare the original and current one, use
ChangeToken.isDifferent(ChangeToken)
, orisDifferent(String)
orisDifferent(ByteSeq)
.
Implementations may be based on
byteSource()
(typically irrelevant of encoding and thuscharSource()
), and possibly metadata not available via the Resource API. It may it ignoreAbstractResource.uri()
andAbstractResource.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
LikeChangeToken.isDifferent(ChangeToken)
, but given a String instead of an object.- Parameters:
previousToString
- The output of callingChangeToken.toString()
on a ChangeToken previously obtained fromchangeToken()
for this Resource.- Returns:
- see
ChangeToken.isDifferent(ChangeToken)
-
isDifferent
-