Class FileResource

  • All Implemented Interfaces:
    ConnectorResource, Resource, Serializable

    public class FileResource
    extends Object
    implements ConnectorResource
    FileResources are files or directories on local filesystem. The files and directories are served through URI:s to the client terminal and thus must be registered to an URI context before they can be used. The resource is automatically registered to the application when it is created.
    Since:
    3.0
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Detail

      • FileResource

        public FileResource​(File sourceFile)
        Creates a new file resource for providing given file for client terminals.
        Parameters:
        sourceFile - the file that should be served.
    • Method Detail

      • getStream

        public DownloadStream getStream()
        Description copied from interface: ConnectorResource
        Gets resource as stream.

        Note that this method is called while the session is locked to prevent race conditions but the methods in the returned DownloadStream are assumed to be unrelated to the VaadinSession and are called without holding session locks (to prevent locking the session during long file downloads).

        Specified by:
        getStream in interface ConnectorResource
        Returns:
        A download stream which produces the resource content
      • getSourceFile

        public File getSourceFile()
        Gets the source file.
        Returns:
        the source File.
      • getMIMEType

        public String getMIMEType()
        Description copied from interface: Resource
        Gets the MIME type of the resource.
        Specified by:
        getMIMEType in interface Resource
        Returns:
        the MIME type of the resource.
      • getCacheTime

        public long getCacheTime()
        Gets the length of cache expiration time. This gives the adapter the possibility cache streams sent to the client. The caching may be made in adapter or at the client if the client supports caching. Default is DownloadStream.DEFAULT_CACHETIME.
        Returns:
        Cache time in milliseconds.
      • setCacheTime

        public void setCacheTime​(long cacheTime)
        Sets the length of cache expiration time. This gives the adapter the possibility cache streams sent to the client. The caching may be made in adapter or at the client if the client supports caching. Zero or negavive value disbales the caching of this stream.
        Parameters:
        cacheTime - the cache time in milliseconds.
      • getBufferSize

        public int getBufferSize()
        Gets the size of the download buffer used for this resource.

        If the buffer size is 0, the buffer size is decided by the terminal adapter. The default value is 0.

        Returns:
        the size of the buffer in bytes.
      • setBufferSize

        public void setBufferSize​(int bufferSize)
        Sets the size of the download buffer used for this resource.
        Parameters:
        bufferSize - the size of the buffer in bytes.