Class ResponseEntityHelper


  • public class ResponseEntityHelper
    extends Object
    Helper class for working with ResponseEntity.
    Author:
    Filip Hrisafov
    • Constructor Detail

      • ResponseEntityHelper

        public ResponseEntityHelper​(Collection<MediaType> autoInlineMediaTypes)
    • Method Detail

      • asByteArrayResponseEntity

        public ResponseEntity<Resource> asByteArrayResponseEntity​(InputStream inputStream,
                                                                  String mimeType,
                                                                  String name,
                                                                  Boolean download)
        Create a 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

        Parameters:
        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 header
        name - the filename for the Content-Disposition header
        download - flag indicating the type for the Content-Disposition header
        Returns:
        the ResponseEntity with a status HttpStatus.OK
      • setCharset

        public void setCharset​(Charset charset)