Interface InputStreamFactory

  • All Superinterfaces:
    Serializable
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface InputStreamFactory
    extends Serializable
    Creates input stream instances that provides the actual data of a StreamResource.

    The instance of this class should generate InputStream for the resource.

    Since:
    1.0
    Author:
    Vaadin Ltd
    • Method Detail

      • createInputStream

        InputStream createInputStream()
        Produce InputStream instance to read resource data.

        This method is called under the Vaadin session lock. So it's safe to access the application/session data which is required to produce the InputStream data. The presence of the lock on subsequent access to the InputStream is controlled by requiresLock() method. So createInputStream() method is the best place to do your InputStream initialization.

        Return value may not be null.

        Returns:
        data input stream. May not be null.
      • requiresLock

        default boolean requiresLock()
        If this method returns true (by default) then reading data from input stream (via createInputStream() will be done under session lock and it's safe to access application data within InputStream read methods. Otherwise session lock won't be acquired. In the latter case one must not try to access application data.

        createInputStream() is called under the session lock. Normally it should be enough to get all required data from the application at this point and use it to produce the data via InputStream. In this case one should override requiresLock() method to return false. E.g. if InputStream instance is remote URL input stream then you don't want to lock session on reading data from it.

        Returns:
        true if data from the input stream should be read under the session lock, false otherwise