com.vaadin.flow.server.streams.

Class DownloadResponse

java.lang.Object
com.vaadin.flow.server.streams.DownloadResponse

All Implemented Interfaces:

Serializable

public class DownloadResponse extends Object implements Serializable

Data class containing required information for sending the given input stream to the client.

The given input stream will be read at a later time and will be automatically closed by the caller.

Since:

24.8

See Also:

  • Constructor Details

    • DownloadResponse

      public DownloadResponse(InputStream inputStream, String fileName, String contentType, long contentLength)

      Create a download response with content stream and content data.

      Parameters:

      inputStream - data stream for data to send to client, stream will be closed automatically after use by the caller.

      fileName - name of the file to be downloaded, configured by setting the Content-Disposition header to 'attachment' if the value is not null, otherwise the header is not set

      contentType - content type or a value determined from fileName if null

      contentLength - byte size of a stream or -1 if unknown

  • Method Details

    • getInputStream

      public InputStream getInputStream()

      Get the InputStream to read the content data from.

      InputStream needs to be closed by the called after reading is over.

      Returns:

      content InputStream

    • getFileName

      public String getFileName()

      Get the defined file name.

      Returns:

      file name

    • getContentType

      public String getContentType()

      Get the content type.

      For a null value the type should be gotten from VaadinService.getMimeType(fileName) or be set to default value application/octet-stream

      Returns:

      content type

    • getContentLength

      public long getContentLength()

      Get the defined size for the content or -1 if unknown.

      Returns:

      content size

    • error

      public static DownloadResponse error(int statusCode)

      Generate an error response for download.

      Parameters:

      statusCode - error status code

      Returns:

      DownloadResponse for request

    • error

      public static DownloadResponse error(int statusCode, String message)

      Generate an error response for download with message.

      Parameters:

      statusCode - error status code

      message - error message for details on what went wrong

      Returns:

      DownloadResponse for request

    • error

      public static DownloadResponse error(HttpStatusCode statusCode)

      Generate an error response for download.

      Parameters:

      statusCode - error status code

      Returns:

      DownloadResponse for request

    • error

      public static DownloadResponse error(HttpStatusCode statusCode, String message)

      Generate an error response for download with message.

      Parameters:

      statusCode - error status code

      message - error message for details on what went wrong

      Returns:

      DownloadResponse for request

    • hasError

      public boolean hasError()

      Check if response has an error code.

      Returns:

      true is error code has been set

    • setError

      public void setError(int error)

      Set http error code.

      Parameters:

      error - error code

    • setError

      public void setError(int error, String errorMessage)

      Set http error code and error message.

      Parameters:

      error - error code

      errorMessage - error message

    • setError

      public void setError(HttpStatusCode error)

      Set http error code.

      Parameters:

      error - error code

    • setError

      public void setError(HttpStatusCode error, String errorMessage)

      Set http error code and error message.

      Parameters:

      error - error code

      errorMessage - error message

    • getError

      public int getError()

      Get the set error code.

      Returns:

      error code or -1 if not set

    • getErrorMessage

      public String getErrorMessage()

      Get error message if set for error response.

      Returns:

      error message or null if not set