HttpEntityWrapper entity = (HttpEntityWrapper)response.getEntity(); ReadableByteChannel src = Channels.newChannel(entity.getContent());
@Test public void testBasics() throws Exception { final String s = "Message content"; final StringEntity httpentity = new StringEntity(s, ContentType.TEXT_PLAIN); httpentity.setContentEncoding("blah"); final HttpEntityWrapper wrapped = new HttpEntityWrapper(httpentity); Assert.assertEquals(httpentity.getContentLength(), wrapped.getContentLength()); Assert.assertEquals(httpentity.getContentType(), wrapped.getContentType()); Assert.assertEquals(httpentity.getContentEncoding(), wrapped.getContentEncoding()); Assert.assertEquals(httpentity.isChunked(), wrapped.isChunked()); Assert.assertEquals(httpentity.isRepeatable(), wrapped.isRepeatable()); Assert.assertEquals(httpentity.isStreaming(), wrapped.isStreaming()); Assert.assertNotNull(wrapped.getContent()); }
@Override public InputStream getContent() throws IOException { if (this.buffer != null) { return new ByteArrayInputStream(this.buffer); } return super.getContent(); }
@Override public InputStream getContent() throws IOException { if (this.buffer != null) { return new ByteArrayInputStream(this.buffer); } return super.getContent(); }
@Override public InputStream getContent() throws IOException { return new EofSensorInputStream(super.getContent(), this); }
private InputStream getDecompressingStream() throws IOException { final InputStream in = super.getContent(); return new LazyDecompressingInputStream(in, inputStreamFactory); }
@Override public InputStream getContent() throws IOException { return new EofSensorInputStream(super.getContent(), new EofSensorWatcher() { @Override public boolean eofDetected(final InputStream wrapped) throws IOException { releaseConnection(); return false; } @Override public boolean streamClosed(final InputStream wrapped) throws IOException { releaseConnection(); return false; } @Override public boolean streamAbort(final InputStream wrapped) throws IOException { abortConnection(); return false; } }); }
@Override public InputStream getContent() throws IOException { return new EofSensorInputStream(super.getContent(), new EofSensorWatcher() { @Override public boolean eofDetected(final InputStream wrapped) throws IOException { releaseConnection(); return false; } @Override public boolean streamClosed(final InputStream wrapped) throws IOException { releaseConnection(); return false; } @Override public boolean streamAbort(final InputStream wrapped) throws IOException { abortConnection(); return false; } }); }
private void releaseConnection() throws IOException { try { final HttpClientConnection localConn = connectionHolder.getConnection(); if (localConn != null) { if (requestExecutor.keepAlive(request, response, localConn, context)) { if (super.isStreaming()) { Closer.close(super.getContent()); } connectionHolder.releaseConnection(); } } } finally { connectionHolder.discardConnection(); } }
private void releaseConnection() throws IOException { try { final HttpClientConnection localConn = connectionHolder.getConnection(); if (localConn != null) { if (requestExecutor.keepAlive(request, response, localConn, context)) { if (super.isStreaming()) { Closer.close(super.getContent()); } connectionHolder.releaseConnection(); } } } finally { connectionHolder.discardConnection(); } }