Class ClassResource

  • All Implemented Interfaces:
    ConnectorResource, Resource, java.io.Serializable

    public class ClassResource
    extends java.lang.Object
    implements ConnectorResource
    ClassResource is a named resource accessed with the class loader. This can be used to access resources such as icons, files, etc.
    Since:
    3.0
    Author:
    Vaadin Ltd.
    See Also:
    Class.getResource(java.lang.String), Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassResource​(java.lang.Class<?> associatedClass, java.lang.String resourceName)
      Creates a new application resource instance.
      ClassResource​(java.lang.String resourceName)
      Creates a new application resource instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.Class<?> getAssociatedClass()  
      int getBufferSize()
      Gets the size of the download buffer used for this resource.
      long getCacheTime()
      Gets the length of cache expiration time.
      java.lang.String getFilename()
      Gets the virtual filename for this resource.
      java.lang.String getMIMEType()
      Gets the MIME type of this resource.
      DownloadStream getStream()
      Gets resource as stream.
      void setBufferSize​(int bufferSize)
      Sets the size of the download buffer used for this resource.
      void setCacheTime​(long cacheTime)
      Sets the length of cache expiration time.
      • Methods inherited from class java.lang.Object

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

      • ClassResource

        public ClassResource​(java.lang.String resourceName)
        Creates a new application resource instance. The resource id is relative to the location of the UI of the component using this resource (or the Application if using LegacyWindow).
        Parameters:
        resourceName - the Unique identifier of the resource within the application.
      • ClassResource

        public ClassResource​(java.lang.Class<?> associatedClass,
                             java.lang.String resourceName)
        Creates a new application resource instance.
        Parameters:
        associatedClass - the class of the which the resource is associated.
        resourceName - the Unique identifier of the resource within the application.
    • Method Detail

      • getMIMEType

        public java.lang.String getMIMEType()
        Gets the MIME type of this resource.
        Specified by:
        getMIMEType in interface Resource
        Returns:
        the MIME type of the resource.
        See Also:
        Resource.getMIMEType()
      • getFilename

        public java.lang.String getFilename()
        Description copied from interface: ConnectorResource
        Gets the virtual filename for this resource.
        Specified by:
        getFilename in interface ConnectorResource
        Returns:
        the file name associated to this resource.
      • 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
      • getAssociatedClass

        protected java.lang.Class<?> getAssociatedClass()
      • 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.
        See Also:
        getBufferSize()
      • 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 negative value disables the caching of this stream.

        Parameters:
        cacheTime - the cache time in milliseconds.