|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.basho.riak.client.http.util.ClientUtils
public class ClientUtils
Utility functions.
Constructor Summary | |
---|---|
ClientUtils()
|
Method Summary | |
---|---|
static Map<String,String> |
asHeaderMap(org.apache.http.Header[] headers)
Convert a header array returned from HttpClient to a map |
static byte[] |
bufferStream(InputStream valueStream)
Buffers an input stream into a byte array |
static void |
copyStream(InputStream in,
OutputStream out)
Copies data from an InputStream to an OutputStream in
blocks |
static String |
encodeClientId(byte[] clientId)
Base64 encodes the first 4 bytes of clientId into a value acceptable for the X-Riak-ClientId header. |
static String |
encodeClientId(String clientId)
|
static String |
getPathFromUrl(String url)
Return just the path portion of the given URL |
static String |
join(String[] arr,
String delimiter)
Join the elements in arr in to a single string separated by delimiter. |
static List<String> |
jsonArrayAsList(JSONArray json)
Convert a JSONArray to a list |
static Map<String,String> |
jsonObjectAsMap(JSONObject json)
Convert a JSONObject to a map |
static String |
makeURI(RiakConfig config,
String bucket)
Return a URL to the given bucket |
static String |
makeURI(RiakConfig config,
String bucket,
String key)
Return a URL to the given object |
static String |
makeURI(RiakConfig config,
String bucket,
String index,
int[] values)
Return a URL to the given index |
static String |
makeURI(RiakConfig config,
String bucket,
String key,
String extra)
Return a URL to the given object |
static String |
makeURI(RiakConfig config,
String bucket,
String index,
String[] values)
Return a URL to the given index |
static org.apache.http.client.HttpClient |
newHttpClient(RiakConfig config)
Construct a new HttpClient instance given a RiakConfig . |
static List<RiakIndex> |
parseIndexHeaders(Map<String,String> headers)
Extract X-Riak-Index-* headers and create List of
RiakIndex es from them |
static List<RiakLink> |
parseLinkHeader(String header)
Parse a link header into a RiakLink . |
static List<RiakObject> |
parseMultipart(RiakClient riak,
String bucket,
String key,
Map<String,String> docHeaders,
byte[] docBody)
Convert a multipart/mixed document to a list of RiakObject s. |
static Map<String,String> |
parseUsermeta(Map<String,String> headers)
Extract only the user-specified metadata headers from a header set: all headers prefixed with X-Riak-Meta-. |
static String |
randomClientId()
Returns a random X-Riak-ClientId header value. |
static void |
throwChecked(Throwable exception)
Throws a checked Exception not declared in the method signature,
which can be particularly useful for throwing checked exceptions within a
RiakExceptionHandler . |
static String |
unquoteString(String s)
Unquote and unescape an HTTP quoted-string :
http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2
Does nothing if s is not quoted. |
static String |
urlDecode(String s)
Decodes a UTF-8 encoded string |
static String |
urlEncode(String s)
UTF-8 encode the string |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ClientUtils()
Method Detail |
---|
public static org.apache.http.client.HttpClient newHttpClient(RiakConfig config)
HttpClient
instance given a RiakConfig
.
config
- RiakConfig
containing HttpClient configuration
specifics.
HttpClient
public static String makeURI(RiakConfig config, String bucket)
config
- RiakConfig containing the base URL to Riakbucket
- Bucket whose URL to retrieving
public static String makeURI(RiakConfig config, String bucket, String key)
config
- RiakConfig containing the base URL to Riakbucket
- Bucket of the objectkey
- Key of the object
public static String makeURI(RiakConfig config, String bucket, String key, String extra)
config
- RiakConfig containing the base URL to Riakbucket
- Bucket of the objectkey
- Key of the objectextra
- Extra path information beyond the bucket and key (e.g. for
link walking or query parameters)
public static String makeURI(RiakConfig config, String bucket, String index, String[] values)
config
- RiakConfig containing the base URL to Riakbucket
- Bucket of the objectindex
- index namevalues
- the index value (or values for a range)
public static String makeURI(RiakConfig config, String bucket, String index, int[] values)
config
- RiakConfig containing the base URL to Riakbucket
- Bucket of the objectindex
- index namevalues
- the index value (or values for a range)
public static String getPathFromUrl(String url)
public static String urlEncode(String s)
public static String urlDecode(String s)
public static String encodeClientId(byte[] clientId)
public static String encodeClientId(String clientId)
public static String randomClientId()
public static String unquoteString(String s)
quoted-string
:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2
Does nothing if s
is not quoted.
s
- quoted-string
to unquote
public static Map<String,String> asHeaderMap(org.apache.http.Header[] headers)
HttpClient
to a map
headers
- Header array returned from HttpClient
public static Map<String,String> jsonObjectAsMap(JSONObject json)
JSONObject
to a map
json
- JSONObject
to convert
public static List<String> jsonArrayAsList(JSONArray json)
JSONArray
to a list
json
- JSONArray
to convert
public static String join(String[] arr, String delimiter)
public static void copyStream(InputStream in, OutputStream out) throws IOException
InputStream
to an OutputStream
in
blocks
in
- InputStream to copyout
- OutputStream to copy to
IOException
public static List<RiakLink> parseLinkHeader(String header)
RiakLink
. See LinkHeader
.
header
- The HTTP Link header value.
RiakLink
objects constructed from the links in
header in order.public static List<RiakIndex> parseIndexHeaders(Map<String,String> headers)
List
of
RiakIndex
es from them
headers
- The full HTTP headers from the response
public static Map<String,String> parseUsermeta(Map<String,String> headers)
headers
- The full HTTP header set from the response
public static List<RiakObject> parseMultipart(RiakClient riak, String bucket, String key, Map<String,String> docHeaders, byte[] docBody)
RiakObject
s.
riak
- RiakClient
this object should be associate with, or
null if nonebucket
- original object's bucketkey
- original object's keydocHeaders
- original document's headersdocBody
- original document's body
RiakObject
s represented by the multipart documentpublic static void throwChecked(Throwable exception)
Exception
not declared in the method signature,
which can be particularly useful for throwing checked exceptions within a
RiakExceptionHandler
. Clearly, this circumvents compiler
safeguards, so use with caution. You've been warned.
exception
- A checked (or unchecked) exception to be thrown.public static byte[] bufferStream(InputStream valueStream)
valueStream
- the stream to read into an array
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |