Class InputStreamDataProvider

  • All Implemented Interfaces:
    com.pspdfkit.document.providers.DataProvider

    
    public abstract class InputStreamDataProvider
    extends ContextDataProvider
                        

    Abstract data provider that handles serving a PDF document from an InputStream. Since viewing the PDF document needs random access, this class wraps the logic for re-opening the stream for backwards-seek operations. Subclasses need to override the openInputStream method, which needs to return a new InputStream instance every time it is called.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Array<byte> read(long size, long offset) Called by PSPDFKit to read data from the document.
      void release() Called when the provided document is being closed.
      • Methods inherited from class java.lang.Object

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

      • InputStreamDataProvider

        InputStreamDataProvider()
    • Method Detail

      • read

        @NonNull() Array<byte> read(long size, long offset)

        Called by PSPDFKit to read data from the document. The returned byte array can be reused in subsequent calls to prevent excessive allocations.

        Parameters:
        size - Size of the data chunk to be read in bytes.
        offset - Offset from start of document of the data chunk to be read in bytes.
        Returns:

        Byte array with document data of the exact same size or larger size than size parameter. Implementations may not return null or loading will fail. Instead, when experiencing a read error, implementations may return NO_DATA_AVAILABLE to safely stop reading.

      • release

         void release()

        Called when the provided document is being closed. Implementations are expected to release all resources (like closing of all streams and freeing of allocations).