public class ClientUtils extends Object
| Constructor and Description |
|---|
ClientUtils() |
| Modifier and Type | Method and Description |
|---|---|
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(org.json.JSONArray json)
Convert a
JSONArray to a list |
static Map<String,String> |
jsonObjectAsMap(org.json.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,
long[] 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 Date |
parseDate(String date) |
static List<RiakIndex> |
parseIndexHeaders(Map<String,String> headers)
|
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
RiakObjects. |
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
|
public static org.apache.http.client.HttpClient newHttpClient(RiakConfig config)
HttpClient instance given a RiakConfig.config - RiakConfig containing HttpClient configuration
specifics.HttpClientpublic static String makeURI(RiakConfig config, String bucket)
config - RiakConfig containing the base URL to Riakbucket - Bucket whose URL to retrievingpublic static String makeURI(RiakConfig config, String bucket, String key)
config - RiakConfig containing the base URL to Riakbucket - Bucket of the objectkey - Key of the objectpublic 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, long[] 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 encodeClientId(byte[] 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 unquotepublic static Map<String,String> asHeaderMap(org.apache.http.Header[] headers)
HttpClient to a mapheaders - Header array returned from HttpClientpublic static Map<String,String> jsonObjectAsMap(org.json.JSONObject json)
JSONObject to a mapjson - JSONObject to convertpublic static List<String> jsonArrayAsList(org.json.JSONArray json)
JSONArray to a listjson - JSONArray to convertpublic static String join(String[] arr, String delimiter)
public static void copyStream(InputStream in, OutputStream out) throws IOException
InputStream to an OutputStream in
blocksin - InputStream to copyout - OutputStream to copy toIOExceptionpublic 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)
headers - The full HTTP headers from the responsepublic static Map<String,String> parseUsermeta(Map<String,String> headers)
headers - The full HTTP header set from the responsepublic static List<RiakObject> parseMultipart(RiakClient riak, String bucket, String key, Map<String,String> docHeaders, byte[] docBody)
RiakObjects.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 bodyRiakObjects 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 arrayCopyright © 2014. All Rights Reserved.