Refine search
@Override protected CompletableFuture<Optional<Object>> send(final Optional<Object> id, final byte[] data) { synchronized (this) { CompletableFuture<Optional<Object>> future = new CompletableFuture<>(); try { out.write(data); out.flush(); future.complete(id); } catch (Throwable ex) { future.completeExceptionally(ex); ifClose(ex); } return future; } }
@Override protected void close() { sender().close(); }
/** * @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); } } }
? ((HttpOutput)out).isWritten() : true; if (LOG.isDebugEnabled()) LOG.debug(String.format("sendData content=%s out=%s async=%b",content,out,request.isAsyncSupported())); ByteBuffer buffer = content.getIndirectBuffer(); if (buffer!=null) BufferUtil.writeTo(buffer,out); else content.getResource().writeTo(out,0,content_length); context.setTimeout(0); ((HttpOutput)out).sendContent(content,new Callback() ((HttpOutput)out).sendContent(content); String mimetype=(content==null?null:content.getContentTypeValue()); if (mimetype==null) LOG.warn("Unknown mimetype for "+request.getRequestURI()); MultiPartOutputStream multi = new MultiPartOutputStream(out); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
@Override protected Action process() throws Exception { // Only return if EOF has previously been read and thus // a write done with EOF=true if (_eof) { if (LOG.isDebugEnabled()) LOG.debug("EOF of {}",this); _in.close(); closed(); _channel.getByteBufferPool().release(_buffer); return Action.SUCCEEDED; } // Read from stream until buffer full or EOF BufferUtil.clearToFill(_buffer); while (_buffer.hasRemaining() && !_eof) _eof = (_in.read(_buffer)) < 0; // write what we have BufferUtil.flipToFlush(_buffer, 0); write(_buffer,_eof,this); return Action.SCHEDULED; }
? ((HttpOutput)out).isWritten() : true; if (LOG.isDebugEnabled()) LOG.debug(String.format("sendData content=%s out=%s async=%b",content,out,request.isAsyncSupported())); ByteBuffer buffer = (content==null)?null:content.getIndirectBuffer(); if (buffer!=null) BufferUtil.writeTo(buffer,out); else resource.writeTo(out,0,content_length); writeOptionHeaders(r.getHttpFields()); r.setHeaders(content); context.setTimeout(0); ((HttpOutput)out).sendContent(content,new Callback() ((HttpOutput)out).sendContent(content); String mimetype=(content==null?null:content.getContentType()); if (mimetype==null) LOG.warn("Unknown mimetype for "+request.getRequestURI()); MultiPartOutputStream multi = new MultiPartOutputStream(out); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
/** * Blocking send of whole content. * * @param content The whole content to send * @throws IOException if the send fails */ public void sendContent(ByteBuffer content) throws IOException { if (LOG.isDebugEnabled()) LOG.debug("sendContent({})",BufferUtil.toDetailString(content)); write(content, true); closed(); }
private void write(ByteBuffer content, boolean complete) throws IOException { try (Blocker blocker = _writeBlock.acquire()) { write(content, complete, blocker); blocker.block(); } catch (Exception failure) { if (LOG.isDebugEnabled()) LOG.debug(failure); abort(failure); if (failure instanceof IOException) throw failure; throw new IOException(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; } }
Connector connector = HttpChannel.getCurrentHttpChannel().getConnector(); direct=false; content_length=content.getContentLength(); ? ((HttpOutput)out).isWritten() : true; writeOptionHeaders(((Response)response).getHttpFields()); ((HttpOutput)out).sendContent(content); ((HttpOutput)out).sendContent(buffer); BufferUtil.writeTo(buffer,out); else resource.writeTo(out,0,content_length); String mimetype=(content.getContentType()==null?null:content.getContentType().toString()); if (mimetype==null) LOG.warn("Unknown mimetype for "+request.getRequestURI()); MultiPartOutputStream multi = new MultiPartOutputStream(out); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
? ((HttpOutput)out).isWritten() : AbstractHttpConnection.getCurrentConnection().getGenerator().isWritten(); writeOptionHeaders(((Response)response).getHttpFields()); ((AbstractHttpConnection.Output)out).sendContent(content); String mimetype=(content.getContentType()==null?null:content.getContentType().toString()); if (mimetype==null) LOG.warn("Unknown mimetype for "+request.getRequestURI()); MultiPartOutputStream multi = new MultiPartOutputStream(out); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
@Override public void close() { if (!isClosed()) { try { if (BufferUtil.hasContent(_aggregate)) _channel.write(_aggregate, !_channel.getResponse().isIncluding()); else _channel.write(BufferUtil.EMPTY_BUFFER, !_channel.getResponse().isIncluding()); } catch(IOException e) { _channel.getEndPoint().shutdownOutput(); LOG.ignore(e); } } closed(); }
public void reset() { HttpConfiguration config = _channel.getHttpConfiguration(); _bufferSize = config.getOutputBufferSize(); _commitSize = config.getOutputAggregationSize(); if (_commitSize>_bufferSize) { LOG.warn("OutputAggregationSize {} exceeds bufferSize {}",_commitSize,_bufferSize); _commitSize=_bufferSize; } _written = 0; reopen(); }
@Override public void print(String s) throws IOException { if (isClosed()) throw new IOException("Closed"); write(s.getBytes(_channel.getResponse().getCharacterEncoding())); }
@Override public void write(int b) throws IOException { if (isClosed()) throw new EOFException("Closed"); if (_aggregate == null) _aggregate = _channel.getByteBufferPool().acquire(getBufferSize(), OUTPUT_BUFFER_DIRECT); BufferUtil.append(_aggregate, (byte)b); _written++; // Check if all written or full if (!closeIfAllContentWritten() && BufferUtil.isFull(_aggregate)) _channel.write(_aggregate, false); }
if (isCommitted() || isIncluding()) return; if (_contentLength > 0) long written = _out.getWritten(); if (written > len) throw new IllegalArgumentException("setContentLength(" + len + ") when already written " + written); if (isAllContentWritten(written)) long written = _out.getWritten(); if (written > 0) throw new IllegalArgumentException("setContentLength(0) when already written " + written);
public void resetBuffer() { _written = 0; if (BufferUtil.hasContent(_aggregate)) BufferUtil.clear(_aggregate); reopen(); }
@Override public void setContentLength(int len) { // Protect from setting after committed as default handling // of a servlet HEAD request ALWAYS sets _content length, even // if the getHandling committed the response! if (isCommitted() || isIncluding()) return; long written = _out.getWritten(); if (written > len) throw new IllegalArgumentException("setContentLength(" + len + ") when already written " + written); _contentLength = len; _fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), len); if (_contentLength > 0) { try { closeIfAllContentWritten(written); } catch(IOException e) { throw new RuntimeIOException(e); } } }
@Override public void resetBuffer() { if (isCommitted()) throw new IllegalStateException("Committed"); switch (_outputType) { case STREAM: case WRITER: _out.reset(); } _out.resetBuffer(); }
private void invoke(ServiceRequestContext ctx, HttpResponseWriter res, ArmeriaHttpTransport transport, HttpChannel httpChannel) { final Queue<HttpData> out = transport.out; try { server.handle(httpChannel); httpChannel.getResponse().getHttpOutput().flush(); final Throwable cause = transport.cause; if (cause != null) { throw cause; } final HttpHeaders headers = toResponseHeaders(transport); if (res.tryWrite(headers)) { for (;;) { final HttpData data = out.poll(); if (data == null || !res.tryWrite(data)) { break; } } } } catch (Throwable t) { logger.warn("{} Failed to produce a response:", ctx, t); } finally { res.close(); } }