Class HttpComponentsHttpResponse
- All Implemented Interfaces:
- HttpResponse,- Response
public class HttpComponentsHttpResponse extends AbstractHttpResponse
AbstractHttpResponse that implements
 missing methods by wrapping an Apache HTTP Components HttpResponse.
 A typical use case of this class is storing in a WarcRecord the
 content of an Apache HTTP Components HttpResponse. The nested
 class HttpComponentsHttpResponse.HttpResponseHeaderMap can be used in other classes to expose
 as a standard Java map the header-related methods of an Apache HTTP Components HttpResponse.
 
To be able to return a MeasurableInputStream, this class caches the
 result of the underlying Apache HTTP Components HttpResponse. The cache
 is never shrunk, but clear() will trim it to length zero. You can override
 contentAsStream() to provide different ways of perform the caching.
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classHttpComponentsHttpResponse.HttpResponseHeaderMapA wrapper class exposing headers inHttpResponse.headers()format by delegating to anHttpResponse.
- 
Field SummaryFields Modifier and Type Field Description protected FastByteArrayOutputStreamcachedContentA cache for the content of the entity returned byhttpResponse.protected booleancontentReadyWhether the content of the entity returned byhttpResponsehas been cached incachedContent.protected HttpComponentsHttpResponse.HttpResponseHeaderMapheaderMapThe header map wrappinghttpResponse's headers.protected org.apache.http.HttpResponsehttpResponseThe response wrapped by thisHttpComponentsHttpResponse.protected URIurlThe URL associated withhttpResponse.Fields inherited from class it.unimi.dsi.law.warc.util.AbstractHttpResponserandomFields inherited from interface it.unimi.dsi.law.warc.util.HttpResponseDIGEST_HEADER, GUESSED_CHARSET_HEADER, HEADER_CHARSET, ISDUPLICATE_HEADER
- 
Constructor SummaryConstructors Constructor Description HttpComponentsHttpResponse()Creates a new instance.HttpComponentsHttpResponse(URI url, org.apache.http.HttpResponse httpResponse)Creates a new instance wrapping a given Apache HTTP ComponentsHttpResponse.
- 
Method SummaryModifier and Type Method Description voidclear()Clears thisHttpComponentsHttpResponse, in particular trimming the content cache.voidconsume()InvokesEntityUtils.consume(HttpEntity)on the entity returned by the underlying Apache HTTP ComponentsHttpResponse.MeasurableInputStreamcontentAsStream()Returns the content of this response as a stream.booleanfromWarcRecord(WarcRecord record)Fills this response with the content of aWarcRecord(optional operation).Map<String,String>headers()Returns the headers of this response.voidset(URI url, org.apache.http.HttpResponse httpResponse)Sets the response wrapped by this instance.intstatus()Returns the response status.org.apache.http.StatusLinestatusLine()Returns the response status line.URIuri()Returns the URI associated with this response.Methods inherited from class it.unimi.dsi.law.warc.util.AbstractHttpResponsetoWarcRecord
- 
Field Details- 
urlThe URL associated withhttpResponse.
- 
httpResponseprotected org.apache.http.HttpResponse httpResponseThe response wrapped by thisHttpComponentsHttpResponse.
- 
headerMapThe header map wrappinghttpResponse's headers.
- 
cachedContentA cache for the content of the entity returned byhttpResponse.
- 
contentReadyprotected boolean contentReadyWhether the content of the entity returned byhttpResponsehas been cached incachedContent.
 
- 
- 
Constructor Details- 
HttpComponentsHttpResponsepublic HttpComponentsHttpResponse()Creates a new instance.Use set(URI, HttpResponse)to wrap an Apache HTTP ComponentsHttpResponse.
- 
HttpComponentsHttpResponseCreates a new instance wrapping a given Apache HTTP ComponentsHttpResponse.- Parameters:
- url- the URL for- httpResponse.
- httpResponse- the response to be wrapped.
 
 
- 
- 
Method Details- 
setSets the response wrapped by this instance.- Parameters:
- url- the URL for- httpResponse.
- httpResponse- the response to be wrapped.
 
- 
consumeInvokesEntityUtils.consume(HttpEntity)on the entity returned by the underlying Apache HTTP ComponentsHttpResponse.- Throws:
- IOException
 
- 
statuspublic int status()Description copied from interface:HttpResponseReturns the response status.- Returns:
- the status of this response.
 
- 
statusLinepublic org.apache.http.StatusLine statusLine()Description copied from interface:HttpResponseReturns the response status line.- Returns:
- the status line of this response.
 
- 
headersDescription copied from interface:HttpResponseReturns the headers of this response.Warning: as of LAW 3.0, and contrarily to previous behaviour, the map is case-sensitive. Use the predefined names in HttpHeadersorHttpHeadersto avoid typing and casing mistakes.- Returns:
- the headers of this response.
 
- 
contentAsStreamDescription copied from interface:HttpResponseReturns the content of this response as a stream.- Returns:
- the content of this response as a stream.
- Throws:
- IOException
 
- 
uriDescription copied from interface:ResponseReturns the URI associated with this response.- Returns:
- the URI associated with this response.
 
- 
fromWarcRecordDescription copied from interface:ResponseFills this response with the content of aWarcRecord(optional operation).- Parameters:
- record- the record.
- Returns:
- true iff the  record-typeof the given record isresponse.
- Throws:
- IOException
 
- 
clearpublic void clear()Clears thisHttpComponentsHttpResponse, in particular trimming the content cache.
 
-