public class ResponseEntityHelper extends Object
ResponseEntity
.Modifier and Type | Field and Description |
---|---|
protected Collection<MediaType> |
autoInlineMediaTypes |
protected Charset |
charset |
Constructor and Description |
---|
ResponseEntityHelper(Collection<MediaType> autoInlineMediaTypes) |
Modifier and Type | Method and Description |
---|---|
ResponseEntity<byte[]> |
asByteArrayResponseEntity(InputStream inputStream,
String mimeType,
String name,
Boolean download)
|
protected String |
dispositionType(Boolean download,
MediaType mediaType) |
void |
setCharset(Charset charset) |
protected Collection<MediaType> autoInlineMediaTypes
protected Charset charset
public ResponseEntityHelper(Collection<MediaType> autoInlineMediaTypes)
public ResponseEntity<byte[]> asByteArrayResponseEntity(InputStream inputStream, String mimeType, String name, Boolean download) throws IOException
ResponseEntity
with a byte[]
body based on the inputStream
.
When the mimeType
is provided and is a known MediaType
then it would be used as the Content-Type
header for the ResponseEntity
.
Otherwise, application/octet-stream
would be used.
If the name
is provided then a Content-Disposition
header would be added
with that as a file name.
The download
flag is used to indicate whether the inputStream
should be
displayed inside the Web page (inline
when download
is false
)
or downloaded (attachment
when download
is true
). In case it is null
the value would be created based on the mimeType
.
NB: Callers of this method are responsible for appropriately closing the inputStream
inputStream
- The input stream that should be used as the body (the caller is responsible for closing it)mimeType
- the mime type for the Content-Type
headername
- the filename for the Content-Disposition
headerdownload
- flag indicating the type for the Content-Disposition
headerResponseEntity
with a status HttpStatus.OK
IOException
- in case of I/O errorspublic void setCharset(Charset charset)