Here are the examples of the java api com.vaadin.flow.server.StreamResource taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
9
Source : StreamResourceHandler.java
with MIT License
from mcollovati
with MIT License
from mcollovati
/**
* Handle sending for a stream resource request.
*
* @param session session for the request
* @param request request to handle
* @param response response object to which a response can be written.
* @param streamResource stream resource that handles data writer
* @throws IOException if an IO error occurred
*/
public void handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamResource streamResource) throws IOException {
StreamResourceWriter writer;
session.lock();
try {
ServletContext context = ((VertxVaadinRequest) request).getService().getServletContext();
response.setContentType(streamResource.getContentTypeResolver().apply(streamResource, context));
response.setCacheTime(streamResource.getCacheTime());
writer = streamResource.getWriter();
if (writer == null) {
throw new IOException("Stream resource produces null input stream");
}
} finally {
session.unlock();
}
try (OutputStream outputStream = response.getOutputStream()) {
writer.accept(outputStream, session);
}
}