private DataInfo toDataInfo(ByteBuffer buffer, boolean close) { return new ByteBufferDataInfo(buffer, close); }
@Override public void onSuccess(Response response) { if (LOG.isDebugEnabled()) LOG.debug("onSuccess called. Closing client stream."); clientStream.data(new ByteBufferDataInfo(BufferUtil.EMPTY_BUFFER, true), LOGGING_CALLBACK); }
ByteBufferDataInfo copyDataInfo = new ByteBufferDataInfo(dataInfo.asByteBuffer(false), dataInfo.isClose(), dataInfo.isCompress())
@Override public void complete() throws IOException { Buffer content = getContentBuffer(); if (content != null) { closed = true; _state = STATE_END; flush(getMaxIdleTime()); } else if (!closed) { closed = true; _state = STATE_END; // Send the last, empty, data frame stream.data(new ByteBufferDataInfo(ZERO_BYTES, true)); } } }
private DataInfo toDataInfo(Buffer buffer, boolean close) { if (buffer instanceof ByteArrayBuffer) return new BytesDataInfo(buffer.array(), buffer.getIndex(), buffer.length(), close); if (buffer instanceof NIOBuffer) { ByteBuffer byteBuffer = ((NIOBuffer)buffer).getByteBuffer(); byteBuffer.limit(buffer.putIndex()); byteBuffer.position(buffer.getIndex()); return new ByteBufferDataInfo(byteBuffer, close); } return new BytesDataInfo(buffer.asArray(), close); }
private DataInfo toDataInfo(Buffer buffer, boolean close) { if (buffer instanceof ByteArrayBuffer) return new BytesDataInfo(buffer.array(), buffer.getIndex(), buffer.length(), close); if (buffer instanceof NIOBuffer) { ByteBuffer byteBuffer = ((NIOBuffer)buffer).getByteBuffer(); byteBuffer.limit(buffer.putIndex()); byteBuffer.position(buffer.getIndex()); return new ByteBufferDataInfo(byteBuffer, close); } return new BytesDataInfo(buffer.asArray(), close); }
@Override public void onContent(final Response response, ByteBuffer content) { if (LOG.isDebugEnabled()) LOG.debug("onContent called with response: {} and content: {}. Sending response content to client.", response, content); final ByteBuffer contentCopy = httpClient.getByteBufferPool().acquire(content.remaining(), true); BufferUtil.flipPutFlip(content, contentCopy); ByteBufferDataInfo dataInfo = new ByteBufferDataInfo(contentCopy, false); clientStream.data(dataInfo, new Callback() { @Override public void failed(Throwable x) { LOG.debug("failed: ", x); releaseBuffer(); response.abort(x); } @Override public void succeeded() { releaseBuffer(); } private void releaseBuffer() { httpClient.getByteBufferPool().release(contentCopy); } }); }
LOG.debug("Send content: {} on stream: {} lastContent={}", BufferUtil.toDetailString(content), stream, lastContent); stream.data(new ByteBufferDataInfo(endPoint.getIdleTimeout(), TimeUnit.MILLISECONDS, content, lastContent ), callback); stream.data(new ByteBufferDataInfo(endPoint.getIdleTimeout(), TimeUnit.MILLISECONDS, BufferUtil.EMPTY_BUFFER, lastContent), callback);