Package 

Class SynchronizedResource

  • All Implemented Interfaces:
    org.readium.r2.shared.fetcher.Resource , org.readium.r2.shared.util.SuspendingCloseable

    
    public final class SynchronizedResource
     implements Resource
                        

    Protects the access to a wrapped resource with a mutex to make it thread-safe.

    This doesn't implement ProxyResource to avoid forgetting the synchronization for a future API.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final File file
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      File getFile()
      Link link() Returns the link from which the resource was retrieved.
      Try<Long, Resource.Exception> length() Returns data length from metadata if available, or calculated from reading the bytes otherwise.
      Try<ByteArray, Resource.Exception> read(LongRange range) Reads the bytes at the given range.
      Unit close() Closes this object and releases any resources associated with it.
      String toString()
      • Methods inherited from class org.readium.r2.shared.fetcher.Resource

        readAsBitmap, readAsJson, readAsString, readAsXml
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SynchronizedResource

        SynchronizedResource(Resource resource)
    • Method Detail

      • link

         Link link()

        Returns the link from which the resource was retrieved.

        It might be modified by the Resource to include additional metadata, e.g. the Content-Type HTTP header in Link.type.

      • 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.

      • 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.