@Override public void send(File file) { response.file(file); }
/** * Writes the specified file directly to the response. * <p>This method commits the response.</p> * * @param file */ public void file(File file) { try { contentLength(file.length()); file(file.getName(), new FileInputStream(file)); } catch (FileNotFoundException e) { throw new PippoRuntimeException(e); } }
/** * Serializes the object using the registered ContentTypeEngine matching * the pre-specified content-type. * <p>This method commits the response.</p> * * @param object */ public void send(Object object) { if (object instanceof File) { file((File) object); } else { send(object, getContentType()); } }
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { String filename = resourceUrl.getFile(); String mimeType = routeContext.getApplication().getMimeTypes().getContentType(filename); if (!StringUtils.isNullOrEmpty(mimeType)) { // stream the resource log.debug("Streaming as resource '{}'", resourceUrl); routeContext.getResponse().ok().chunked(chunked).resource(resourceUrl.openStream()); } else { // stream the file log.debug("Streaming as file '{}'", resourceUrl); routeContext.getResponse().ok().chunked(chunked).file(filename, resourceUrl.openStream()); } }
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException { String filename = resourceUrl.getFile(); String mimeType = routeContext.getApplication().getMimeTypes().getContentType(filename); if (!StringUtils.isNullOrEmpty(mimeType)) { // stream the resource log.debug("Streaming as resource '{}'", resourceUrl); routeContext.getResponse().contentType(mimeType); routeContext.getResponse().ok().resource(resourceUrl.openStream()); } else { // stream the file log.debug("Streaming as file '{}'", resourceUrl); routeContext.getResponse().ok().file(filename, resourceUrl.openStream()); } }