Class StreamResource

    • Constructor Detail

      • StreamResource

        public StreamResource​(String name,
                              StreamResourceWriter writer)
        Creates StreamResource instance using mandatory parameters name as a resource file name and output stream writer as a data producer. writer should write data in the output stream provided as an argument to its StreamResourceWriter.accept(OutputStream, VaadinSession) method.

        name parameter value will be used in URI (generated when resource is registered) in a way that the name is the last segment of the path. So this is synthetic file name (not real one).

        Parameters:
        name - resource file name. May not be null.
        writer - data output stream consumer
      • StreamResource

        public StreamResource​(String name,
                              InputStreamFactory factory)
        Creates StreamResource instance using mandatory parameters name as a resource file name and input stream factory as a factory for data.

        name parameter value will be used in URI (generated when resource is registered) in a way that the name is the last segment of the path. So this is synthetic file name (not real one).

        Parameters:
        name - resource file name. May not be null.
        factory - data input stream factory. May not be null.
    • Method Detail

      • setContentTypeResolver

        public StreamResource setContentTypeResolver​(ContentTypeResolver resolver)
        Sets the resolver which is used to lookup the content type of the resource.

        By default a resolver based on servletContext.getMimeType() is used.

        Parameters:
        resolver - content type resolver, not null
        Returns:
        this resource
      • getContentTypeResolver

        public ContentTypeResolver getContentTypeResolver()
        Gets the resolver which is used to lookup the content type of the resource.
        Returns:
        content type resolver
      • setHeader

        public StreamResource setHeader​(String name,
                                        String value)
        Sets the value of a generic response header. If the header had already been set, the new value overwrites the previous one.
        Parameters:
        name - a header name
        value - value of the header
        Returns:
        this resource
      • getHeader

        public Optional<String> getHeader​(String name)
        Gets the value for header name set for the resource.
        Parameters:
        name - name of header to get value for
        Returns:
        an optional with header value, or an empty optional if it has not been set
      • getName

        public String getName()
        Description copied from class: AbstractStreamResource
        Get the resource name.

        The value will be used in URI (generated when resource is registered) in a way that the name is the last segment of the path. So this is a synthetic name.

        Specified by:
        getName in class AbstractStreamResource
        Returns:
        resource name