com.basho.riak.client.http.response
Class FetchResponse

java.lang.Object
  extended by com.basho.riak.client.http.response.HttpResponseDecorator
      extended by com.basho.riak.client.http.response.FetchResponse
All Implemented Interfaces:
HttpResponse, WithBodyResponse

public class FetchResponse
extends HttpResponseDecorator
implements WithBodyResponse

Response from a HEAD or GET request for an object. Decorates an HttpResponse to interpret fetch and fetchMeta responses from Riak's HTTP interface which returns object metadata in HTTP headers and value in the body.


Field Summary
 
Fields inherited from class com.basho.riak.client.http.response.HttpResponseDecorator
impl
 
Constructor Summary
FetchResponse(HttpResponse r)
           
FetchResponse(HttpResponse r, RiakClient riak)
          On a 2xx response, parse the HTTP response from Riak into a RiakObject.
 
Method Summary
 RiakObject getObject()
          Returns the first Riak object contained in the response.
 Collection<RiakObject> getSiblings()
          Returns a collection of the Riak objects contained in the response.
 String getVclock()
           
 boolean hasObject()
          Whether response contained a Riak object
 boolean hasSiblings()
          Whether response contained a multiple Riak objects
 void setObject(RiakObject object)
           
 
Methods inherited from class com.basho.riak.client.http.response.HttpResponseDecorator
close, getBody, getBodyAsString, getBucket, getHttpHeaders, getHttpMethod, getHttpResponse, getKey, getStatusCode, getStream, isError, isStreamed, isSuccess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.basho.riak.client.http.response.HttpResponse
close, getBody, getBodyAsString, getBucket, getHttpHeaders, getHttpMethod, getHttpResponse, getKey, getStatusCode, getStream, isError, isStreamed, isSuccess
 

Constructor Detail

FetchResponse

public FetchResponse(HttpResponse r,
                     RiakClient riak)
              throws RiakResponseRuntimeException,
                     RiakIORuntimeException
On a 2xx response, parse the HTTP response from Riak into a RiakObject. On a 300 response, parse the multipart/mixed HTTP body into a collection of sibling RiakObjects. A streaming response (i.e. r.isStreaming() == true), will have a null body and non-null stream. The resulting RiakObject(s) will return null for getValue() and the stream for getValueStream(). Users must remember to release the return value's underlying stream by calling close(). Sibling objects are also streamed. The values of the objects are buffered in memory as the stream is read. Consume and/or close each RiakObject's stream as the collection is iterated to allow the buffers to be freed.

Throws:
RiakResponseRuntimeException - If the server returns a 300 without a proper multipart/mixed body or the server returns a 400 Bad Request or 5xx failure
RiakIORuntimeException - If an error occurs during communication with the Riak server.

FetchResponse

public FetchResponse(HttpResponse r)
              throws RiakResponseRuntimeException
Throws:
RiakResponseRuntimeException
Method Detail

hasObject

public boolean hasObject()
Whether response contained a Riak object

Specified by:
hasObject in interface WithBodyResponse

getObject

public RiakObject getObject()
Returns the first Riak object contained in the response. Equivalent to the first object in getSiblings() when hasSiblings() is true.

Specified by:
getObject in interface WithBodyResponse

setObject

public void setObject(RiakObject object)

hasSiblings

public boolean hasSiblings()
Whether response contained a multiple Riak objects

Specified by:
hasSiblings in interface WithBodyResponse

getSiblings

public Collection<RiakObject> getSiblings()
Returns a collection of the Riak objects contained in the response.

Specified by:
getSiblings in interface WithBodyResponse

getVclock

public String getVclock()
Specified by:
getVclock in interface WithBodyResponse
Returns:
the X-Riak-Vclock header value, if present.


Copyright © 2012. All Rights Reserved.