spark.utils.GzipUtils Java Examples
The following examples show how to use
spark.utils.GzipUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tools.java From torrenttunes-client with GNU General Public License v3.0 | 6 votes |
public static Boolean writeFileToResponse(String path, Request req, Response res) { try { OutputStream wrappedOutputStream = GzipUtils.checkAndWrap(req.raw(), res.raw()); IOUtils.copy(new FileInputStream(new File(path)), wrappedOutputStream); wrappedOutputStream.flush(); wrappedOutputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; }
Example #2
Source File: ResolvedContentRoute.java From cineast with MIT License | 5 votes |
@Override public Object handle(Request request, Response response) throws Exception { Map<String, String> params = request.params(); String id; if (params != null && params.containsKey(":id")) { id = params.get(":id"); } else { response.status(400); response.raw().getWriter().write("Bad request"); response.raw().getWriter().flush(); return 404; } ResolutionResult rresult = this.resolver.resolve(id); if (rresult == null) { response.status(400); response.raw().getWriter().write("Bad request"); response.raw().getWriter().flush(); return 404; } response.type(rresult.mimeType); try (InputStream inputStream = rresult.stream; OutputStream wrappedOutputStream = GzipUtils.checkAndWrap(request.raw(), response.raw(), false)) { IOUtils.copy(inputStream, wrappedOutputStream); wrappedOutputStream.flush(); response.raw().getOutputStream().close(); } return 200; }
Example #3
Source File: StaticFileHandlerFilter.java From ache with Apache License 2.0 | 5 votes |
private void writeResponse(Request request, Response response, String file) { OutputStream wrappedOutputStream; try { response.header("Content-Type", "text/html"); response.status(200); wrappedOutputStream = GzipUtils.checkAndWrap(request.raw(), response.raw(), false); IOUtils.copy(new StringInputStream(file), wrappedOutputStream); wrappedOutputStream.flush(); wrappedOutputStream.close(); } catch (IOException e) { throw new RuntimeException("Failed to write HTTP response", e); } }