private static void writeBootstrapPage(VaadinResponse response, String html) throws IOException { response.setContentType( ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(response.getOutputStream(), UTF_8))) { writer.append(html); } }
/** * Writes the given string as a response using the given content type. * * @param response * The response reference * @param contentType * The content type of the response * @param responseString * The actual response * @throws IOException * If an error occurred while writing the response */ public void writeStringResponse(VaadinResponse response, String contentType, String responseString) throws IOException { response.setContentType(contentType); final OutputStream out = response.getOutputStream(); final PrintWriter outWriter = new PrintWriter( new BufferedWriter(new OutputStreamWriter(out, UTF_8))); outWriter.print(responseString); outWriter.close(); }
/** * Build response for handled download. * * @param response * response to write to * @throws IOException * exception when writing to stream */ private void sendUploadResponse(VaadinResponse response) throws IOException { response.setContentType( ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); try (OutputStream out = response.getOutputStream()) { final PrintWriter outWriter = new PrintWriter( new BufferedWriter(new OutputStreamWriter(out, UTF_8))); try { outWriter.print("<html><body>download handled</body></html>"); } finally { outWriter.flush(); } } }
/** * Commit the JSON response. We can't write immediately to the output stream * as we want to write only a critical notification if something goes wrong * during the response handling. * * @param response * The response to write to * @param json * The JSON to write * @throws IOException * If there was an exception while writing to the output */ public static void commitJsonResponse(VaadinResponse response, String json) throws IOException { response.setContentType(JsonConstants.JSON_CONTENT_TYPE); // Ensure that the browser does not cache UIDL responses. // iOS 6 Safari requires this (#9732) response.setHeader("Cache-Control", "no-cache"); byte[] b = json.getBytes(UTF_8); response.setContentLength(b.length); OutputStream outputStream = response.getOutputStream(); outputStream.write(b); // NOTE GateIn requires the buffers to be flushed to work outputStream.flush(); } }
"no-cache, must-revalidate"); try (OutputStream out = response.getOutputStream()) { icon.write(out);
session.unlock(); try (OutputStream outputStream = response.getOutputStream()) { writer.accept(outputStream, session);