-
- All Implemented Interfaces:
-
org.readium.r2.shared.util.SuspendingCloseable
public interface Resource implements SuspendingCloseable
Acts as a proxy to an actual resource by handling read access.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classResource.Companionpublic classResource.ExceptionErrors occurring while accessing a resource.
-
Method Summary
Modifier and Type Method Description abstract Linklink()Returns the link from which the resource was retrieved. abstract Try<Long, Resource.Exception>length()Returns data length from metadata if available, or calculated from reading the bytes otherwise. abstract Try<ByteArray, Resource.Exception>read(LongRange range)Reads the bytes at the given range. Try<String, Resource.Exception>readAsString(Charset charset)Reads the full content as a String. Try<JSONObject, Resource.Exception>readAsJson()Reads the full content as a JSON object. Try<ElementNode, Resource.Exception>readAsXml()Reads the full content as an XML document. Try<Bitmap, Resource.Exception>readAsBitmap()Reads the full content as a Bitmap. FilegetFile()-
-
Method Detail
-
length
abstract 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.
-
read
abstract 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.
-
readAsString
Try<String, Resource.Exception> readAsString(Charset charset)
-
readAsJson
Try<JSONObject, Resource.Exception> readAsJson()
Reads the full content as a JSON object.
-
readAsXml
Try<ElementNode, Resource.Exception> readAsXml()
Reads the full content as an XML document.
-
readAsBitmap
Try<Bitmap, Resource.Exception> readAsBitmap()
Reads the full content as a Bitmap.
-
-
-
-