/** * @param repository * the repository storing large objects * @param context * the servlet asynchronous context * @param response * the servlet response * @param id * id of the object to be downloaded * @throws IOException */ public ObjectDownloadListener(FileLfsRepository repository, AsyncContext context, HttpServletResponse response, AnyLongObjectId id) throws IOException { this.context = context; this.response = response; this.in = repository.getReadChannel(id); this.out = response.getOutputStream(); this.outChannel = Channels.newChannel(out); response.addHeader(HttpSupport.HDR_CONTENT_LENGTH, String.valueOf(repository.getSize(id))); response.setContentType(Constants.HDR_APPLICATION_OCTET_STREAM); }
/** * <p>Constructor for ObjectDownloadListener.</p> * * @param repository * the repository storing large objects * @param context * the servlet asynchronous context * @param response * the servlet response * @param id * id of the object to be downloaded * @throws java.io.IOException */ public ObjectDownloadListener(FileLfsRepository repository, AsyncContext context, HttpServletResponse response, AnyLongObjectId id) throws IOException { this.context = context; this.response = response; this.in = repository.getReadChannel(id); this.out = response.getOutputStream(); this.outChannel = Channels.newChannel(out); response.addHeader(HttpSupport.HDR_CONTENT_LENGTH, String.valueOf(repository.getSize(id))); response.setContentType(Constants.HDR_APPLICATION_OCTET_STREAM); }
/** * {@inheritDoc} * * Handle object downloads */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { AnyLongObjectId obj = getObjectToTransfer(req, rsp); if (obj != null) { if (repository.getSize(obj) == -1) { sendError(rsp, HttpStatus.SC_NOT_FOUND, MessageFormat .format(LfsServerText.get().objectNotFound, obj.getName())); return; } AsyncContext context = req.startAsync(); context.setTimeout(timeout); rsp.getOutputStream() .setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj)); } }
/** * Handles object downloads * * @param req * servlet request * @param rsp * servlet response * @throws ServletException * if a servlet-specific error occurs * @throws IOException * if an I/O error occurs */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { AnyLongObjectId obj = getObjectToTransfer(req, rsp); if (obj != null) { if (repository.getSize(obj) == -1) { sendError(rsp, HttpStatus.SC_NOT_FOUND, MessageFormat .format(LfsServerText.get().objectNotFound, obj.getName())); return; } AsyncContext context = req.startAsync(); context.setTimeout(timeout); rsp.getOutputStream() .setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj)); } }