Package com.vaadin.flow.server.streams
Class DownloadResponse
java.lang.Object
com.vaadin.flow.server.streams.DownloadResponse
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionDownloadResponse(InputStream inputStream, String fileName, String contentType, long contentLength) Create a download response with content stream and content data. -
Method Summary
Modifier and TypeMethodDescriptionstatic DownloadResponseerror(int statusCode) Generate an error response for download.static DownloadResponseGenerate an error response for download.static DownloadResponseGenerate an error response for download with message.static DownloadResponseGenerate an error response for download with message.static DownloadResponseerror(HttpStatusCode statusCode) Generate an error response for download.static DownloadResponseerror(HttpStatusCode statusCode, Exception exception) Generate an error response for download.static DownloadResponseerror(HttpStatusCode statusCode, String message) Generate an error response for download with message.static DownloadResponseerror(HttpStatusCode statusCode, String message, Exception exception) Generate an error response for download with message.longGet the defined size for the content or-1if unknown.Get the content type.intgetError()Get the set error code.Get error message if set for error response.Get the exception that occurred during the download process, if any.Get the defined file name.Get the InputStream to read the content data from.booleanhasError()Check if response has an error code.voidsetError(int error) Set http error code.voidSet http error code.voidSet http error code and error message.voidSet http error code and error message.voidsetError(HttpStatusCode error) Set http error code.voidsetError(HttpStatusCode error, Exception exception) Set http error code.voidsetError(HttpStatusCode error, String errorMessage) Set http error code and error message.voidsetError(HttpStatusCode error, String errorMessage, Exception exception) Set http error code and error message.
-
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 notnull, otherwise the header is not setcontentType- content type or a value determined from fileName ifnullcontentLength- byte size of a stream or-1if unknown
-
-
Method Details
-
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
Get the defined file name.- Returns:
- file name
-
getContentType
Get the content type.For a
nullvalue the type should be gotten fromVaadinService.getMimeType(fileName)or be set to default valueapplication/octet-stream- Returns:
- content type
-
getContentLength
public long getContentLength()Get the defined size for the content or-1if unknown.- Returns:
- content size
-
error
Generate an error response for download.- Parameters:
statusCode- error status code- Returns:
- DownloadResponse for request
-
error
Generate an error response for download.- Parameters:
statusCode- error status codeexception- exception that caused the error- Returns:
- DownloadResponse for request
-
error
Generate an error response for download with message.- Parameters:
statusCode- error status codemessage- error message for details on what went wrong- Returns:
- DownloadResponse for request
-
error
Generate an error response for download with message.- Parameters:
statusCode- error status codemessage- error message for details on what went wrongexception- exception that caused the error- Returns:
- DownloadResponse for request
-
error
Generate an error response for download.- Parameters:
statusCode- error status code- Returns:
- DownloadResponse for request
-
error
Generate an error response for download.- Parameters:
statusCode- error status codeexception- exception that caused the error- Returns:
- DownloadResponse for request
-
error
Generate an error response for download with message.- Parameters:
statusCode- error status codemessage- error message for details on what went wrong- Returns:
- DownloadResponse for request
-
error
public static DownloadResponse error(HttpStatusCode statusCode, String message, Exception exception) Generate an error response for download with message.- Parameters:
statusCode- error status codemessage- error message for details on what went wrongexception- exception that caused the error- Returns:
- DownloadResponse for request
-
hasError
public boolean hasError()Check if response has an error code.- Returns:
trueis error code has been set
-
setError
public void setError(int error) Set http error code.- Parameters:
error- error code
-
setError
Set http error code.- Parameters:
error- error codeexception- exception that caused the error
-
setError
Set http error code and error message.- Parameters:
error- error codeerrorMessage- error message
-
setError
Set http error code and error message.- Parameters:
error- error codeerrorMessage- error messageexception- exception that caused the error
-
setError
Set http error code.- Parameters:
error- error code
-
setError
Set http error code.- Parameters:
error- error codeexception- exception that caused the error
-
setError
Set http error code and error message.- Parameters:
error- error codeerrorMessage- error message
-
setError
Set http error code and error message.- Parameters:
error- error codeerrorMessage- error messageexception- exception that caused the error
-
getError
public int getError()Get the set error code.- Returns:
- error code or -1 if not set
-
getErrorMessage
Get error message if set for error response.- Returns:
- error message or null if not set
-
getException
Get the exception that occurred during the download process, if any.- Returns:
- the exception or null if no exception occurred
- See Also:
-