/** * @param response Http response. * @param type Type. * @param stream Stream. * @param attachmentName Attachment name. * @throws IOException If failed. */ private static void handleRequest(HttpServletResponse response, String type, InputStream stream, String attachmentName) throws IOException { response.setContentType(type); response.setHeader("Content-Disposition", "attachment; filename=\"" + attachmentName + "\""); try (HttpOutput out = (HttpOutput)response.getOutputStream()) { out.sendContent(stream); } } }
/** * @param response Http response. * @param type Type. * @param path Path to file. * @throws IOException If failed. */ private static void handleRequest(HttpServletResponse response, String type, String path) throws IOException { Path path0 = Paths.get(path); response.setContentType(type); response.setHeader("Content-Disposition", "attachment; filename=\"" + path0.getFileName() + "\""); try (HttpOutput out = (HttpOutput)response.getOutputStream()) { out.sendContent(FileChannel.open(path0, StandardOpenOption.READ)); } }
@Override public void send(final byte[] bytes) throws Exception { rsp.setHeader("Transfer-Encoding", null); sender().sendContent(ByteBuffer.wrap(bytes)); }
@Override public void send(final ByteBuffer buffer) throws Exception { sender().sendContent(buffer); }
@Override public void send(final InputStream stream) throws Exception { endRequest = false; startAsyncIfNeedIt(); sender().sendContent(Channels.newChannel(stream), this); }
@Override public void send(final FileChannel channel) throws Exception { int bufferSize = rsp.getBufferSize(); if (channel.size() < bufferSize) { // sync version, file size is smaller than bufferSize sender().sendContent(channel); } else { endRequest = false; startAsyncIfNeedIt(); sender().sendContent(channel, this); } }
@Override public void handle(String pathInContext, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { request.getResponse().getHttpOutput().sendContent(EofTerminatedTest.class.getClassLoader().getResourceAsStream("SimpleTextFile.txt")); } }
private boolean sendContent(Class<?> type, InputStream c) throws IOException { try { out.sendContent(c); } catch (Exception e) { return false; } return true; } @Override
private boolean sendContent(Class<?> type, InputStream c) throws IOException { try { out.sendContent(c); } catch (Exception e) { return false; } return true; } @Override
@Override public void send(final byte[] bytes) throws Exception { rsp.setHeader("Transfer-Encoding", null); sender().sendContent(ByteBuffer.wrap(bytes)); }
@Override public void send(final ByteBuffer buffer) throws Exception { sender().sendContent(buffer); }
@Override public void send(final InputStream stream) throws Exception { endRequest = false; startAsyncIfNeedIt(); sender().sendContent(Channels.newChannel(stream), this); }
@Override public void send(final FileChannel channel) throws Exception { int bufferSize = rsp.getBufferSize(); if (channel.size() < bufferSize) { // sync version, file size is smaller than bufferSize sender().sendContent(channel); } else { endRequest = false; startAsyncIfNeedIt(); sender().sendContent(channel, this); } }
/** Blocking send of content. * @param content The content to send * @throws IOException */ public void sendContent(HttpContent content) throws IOException { try(Blocker blocker=_writeblock.acquire()) { sendContent(content,blocker); blocker.block(); } }
((HttpOutput)getServletResponse().getOutputStream()).sendContent(value);
((HttpOutput)getServletResponse().getOutputStream()).sendContent(value);
/** * Blocking send of HTTP content. * * @param content The HTTP content to send * @throws IOException if the send fails */ public void sendContent(HttpContent content) throws IOException { try (Blocker blocker = _writeBlocker.acquire()) { sendContent(content, blocker); blocker.block(); } catch (Throwable failure) { if (LOG.isDebugEnabled()) LOG.debug(failure); abort(failure); throw failure; } }
/** * Blocking send of HTTP content. * * @param content The HTTP content to send * @throws IOException if the send fails */ public void sendContent(HttpContent content) throws IOException { try(Blocker blocker = _writeBlock.acquire()) { sendContent(content, blocker); blocker.block(); } catch (Throwable failure) { if (LOG.isDebugEnabled()) LOG.debug(failure); abort(failure); throw failure; } }
sendContent(buffer, callback); return; sendContent(rbc, callback); return; if (in != null) sendContent(in, callback); return;
LOG.debug("sendContent({}=={},{},direct={})",httpContent,BufferUtil.toDetailString(buffer),callback,_channel.useDirectBuffers()); sendContent(buffer,callback); return; LOG.debug("sendContent({}=={},{},direct={})",httpContent,rbc,callback,_channel.useDirectBuffers()); sendContent(rbc,callback); return; sendContent(in,callback); return;