Package io.varhttp
Interface ResponseStream
- All Known Implementing Classes:
VarResponseStream
public interface ResponseStream
Carrier for http response body stream to be injected into extension point controller methods, to allow the methods to gain access to the response body stream
Example:@Controller(path = "/myPath")
public void myControllerMethod(ResponseStream responseStream) { try (BufferedWriter writer = responseStream.getContentWriter("fileName.csv", "text/csv", StandardCharsets.UTF_8)) { writer.append("fileContent"); } }
-
Method Summary
Modifier and TypeMethodDescriptiongetContentWriter
(String fileName, String contentType, Charset charset) Get writer that writes to response body in streaming way.default OutputStream
getOutputStream
(String contentType) getOutputStream
(String contentType, Charset charset) Get the output-stream of the response.void
void
-
Method Details
-
getContentWriter
Get writer that writes to response body in streaming way. This should trigger file download in browser.- Parameters:
fileName
- Name of file for download eg. name.csvcontentType
- File format eg. text/csv for csv filescharset
- Character encoding of the file content eg. StandardCharsets.UTF-8 for UTF-8 encoding- Returns:
- writer that writes to response body
-
getOutputStream
Get the output-stream of the response. Used to write non-string content.- Parameters:
contentType
- Content format eg. image/png for PNG filescharset
- Character encoding of the file content eg. StandardCharsets.UTF-8 for UTF-8 encoding- Returns:
- the output stream of the response.
-
getOutputStream
-
write
-
write
-