public abstract class

InputStreamDataProvider

extends Object
implements DataProvider
java.lang.Object
   ↳ com.pspdfkit.api.providers.InputStreamDataProvider

Class Overview

Abstract data provider that handles serving data from an InputStream. The 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.

Summary

[Expand]
Inherited Constants
From interface com.pspdfkit.api.providers.DataProvider
Public Constructors
InputStreamDataProvider()
Public Methods
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.
Protected Methods
long getInputStreamPosition()
Returns the current position inside the read InputStream.
abstract InputStream openInputStream()
Subclasses need to override this method and return a readable input stream which serves the data.
final void reopenInputStream()
Close the internal input stream and reopen it.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.pspdfkit.api.providers.DataProvider

Public Constructors

public InputStreamDataProvider ()

Public Methods

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

public 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).

Protected Methods

protected long getInputStreamPosition ()

Returns the current position inside the read InputStream. Every read operation on the data provider will increase this position. To reset the read position to 0 call reopenInputStream().

Returns
  • The current input stream position (in bytes).

protected abstract InputStream openInputStream ()

Subclasses need to override this method and return a readable input stream which serves the data. This method must return a new InputStream instance every time it is called. This is necessary so InputStreamDataProvider can actually "simulate" random data access on the underlying stream.

Returns
  • A new instance of the InputStream that serves the data.
Throws
Exception If the implementation fails to open the input stream for reading.

protected final void reopenInputStream ()

Close the internal input stream and reopen it. This is used to rewind the stream, if it is necessary to "seek backwards". Subclasses may call this method to safely rewind the stream to the beginning.

Throws
Exception If the implementation fails to close or open the input stream for reading.