ErrorResponseProducer( final HttpResponse response, final HttpEntity entity, final boolean keepAlive) { super(); this.response = response; this.entity = entity; if (entity instanceof HttpAsyncContentProducer) { this.contentProducer = (HttpAsyncContentProducer) entity; } else { this.contentProducer = new EntityAsyncContentProducer(entity); } this.keepAlive = keepAlive; }
@Override public void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { if (this.channel == null) { this.channel = Channels.newChannel(this.entity.getContent()); } final int i = this.channel.read(this.buffer); this.buffer.flip(); encoder.write(this.buffer); final boolean buffering = this.buffer.hasRemaining(); this.buffer.compact(); if (i == -1 && !buffering) { encoder.complete(); close(); } }
@Override public void produceContent( final ContentEncoder encoder, final IOControl ioctrl) throws IOException { if (this.channel == null) { this.channel = Channels.newChannel(this.entity.getContent()); } final int i = this.channel.read(this.buffer); this.buffer.flip(); encoder.write(this.buffer); final boolean buffering = this.buffer.hasRemaining(); this.buffer.compact(); if (i == -1 && !buffering) { encoder.complete(); close(); } }
ErrorResponseProducer( final HttpResponse response, final HttpEntity entity, final boolean keepAlive) { super(); this.response = response; this.entity = entity; if (entity instanceof HttpAsyncContentProducer) { this.contentProducer = (HttpAsyncContentProducer) entity; } else { this.contentProducer = new EntityAsyncContentProducer(entity); } this.keepAlive = keepAlive; }
/** * Creates a producer that can be used to transmit the given response * message. If the response message encloses an {@link HttpEntity} * it is also expected to implement {@link HttpAsyncContentProducer}. * * @param response response message. */ public BasicAsyncResponseProducer(final HttpResponse response) { super(); Args.notNull(response, "HTTP response"); this.response = response; final HttpEntity entity = response.getEntity(); if (entity != null) { if (entity instanceof HttpAsyncContentProducer) { this.producer = (HttpAsyncContentProducer) entity; } else { this.producer = new EntityAsyncContentProducer(entity); } } else { this.producer = null; } }
/** * Creates a producer that can be used to transmit the given response * message. If the response message encloses an {@link HttpEntity} * it is also expected to implement {@link HttpAsyncContentProducer}. * * @param response response message. */ public BasicAsyncResponseProducer(final HttpResponse response) { super(); Args.notNull(response, "HTTP response"); this.response = response; final HttpEntity entity = response.getEntity(); if (entity != null) { if (entity instanceof HttpAsyncContentProducer) { this.producer = (HttpAsyncContentProducer) entity; } else { this.producer = new EntityAsyncContentProducer(entity); } } else { this.producer = null; } }
/** * Creates a producer that can be used to transmit the given request * message. If the request message encloses an {@link HttpEntity} * it is also expected to implement {@link HttpAsyncContentProducer}. * * @param target target host. * @param request request message. */ public BasicAsyncRequestProducer(final HttpHost target, final HttpRequest request) { Args.notNull(target, "HTTP host"); Args.notNull(request, "HTTP request"); this.target = target; this.request = request; if (request instanceof HttpEntityEnclosingRequest) { final HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); if (entity != null) { if (entity instanceof HttpAsyncContentProducer) { this.producer = (HttpAsyncContentProducer) entity; } else { this.producer = new EntityAsyncContentProducer(entity); } } else { this.producer = null; } } else { this.producer = null; } }
/** * Creates a producer that can be used to transmit the given request * message. If the request message encloses an {@link HttpEntity} * it is also expected to implement {@link HttpAsyncContentProducer}. * * @param target target host. * @param request request message. */ public BasicAsyncRequestProducer(final HttpHost target, final HttpRequest request) { Args.notNull(target, "HTTP host"); Args.notNull(request, "HTTP request"); this.target = target; this.request = request; if (request instanceof HttpEntityEnclosingRequest) { final HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); if (entity != null) { if (entity instanceof HttpAsyncContentProducer) { this.producer = (HttpAsyncContentProducer) entity; } else { this.producer = new EntityAsyncContentProducer(entity); } } else { this.producer = null; } } else { this.producer = null; } }