-
- All Implemented Interfaces:
-
org.readium.r2.shared.fetcher.Resource,org.readium.r2.shared.util.SuspendingCloseable
public final class FileFetcher.FileResource implements Resource
-
-
Constructor Summary
Constructors Constructor Description FileFetcher.FileResource(Link link, File file)
-
Method Summary
Modifier and Type Method Description final LinkgetLink()FilegetFile()Direct file to this resource, when available. Linklink()Returns the link from which the resource was retrieved. Unitclose()Closes this object and releases any resources associated with it. Try<ByteArray, Resource.Exception>read(LongRange range)Reads the bytes at the given range. Try<Long, Resource.Exception>length()Returns data length from metadata if available, or calculated from reading the bytes otherwise. StringtoString()-
-
Method Detail
-
getFile
File getFile()
Direct file to this resource, when available.
This is meant to be used as an optimization for consumers which can't work efficiently with streams. However, file is not guaranteed to be set, for example if the resource underwent transformations or is being read from an archive. Therefore, consumers should always fallback on regular stream reading, using read or ResourceInputStream.
-
close
Unit close()
Closes this object and releases any resources associated with it. If the object is already closed then invoking this method has no effect.
-
read
Try<ByteArray, Resource.Exception> read(LongRange range)
Reads the bytes at the given range.
When range is null, the whole content is returned. Out-of-range indexes are clamped to the available length automatically.
-
length
Try<Long, Resource.Exception> length()
Returns data length from metadata if available, or calculated from reading the bytes otherwise.
This value must be treated as a hint, as it might not reflect the actual bytes length. To get the real length, you need to read the whole resource.
-
-
-
-