org.elasticsearch.rest.support
Class RestUtils

java.lang.Object
  extended by org.elasticsearch.rest.support.RestUtils

public class RestUtils
extends Object


Field Summary
static PathTrie.Decoder REST_DECODER
           
 
Constructor Summary
RestUtils()
           
 
Method Summary
static String decodeComponent(String s)
          Decodes a bit of an URL encoded by a browser.
static String decodeComponent(String s, Charset charset)
          Decodes a bit of an URL encoded by a browser.
static void decodeQueryString(String s, int fromIndex, Map<String,String> params)
           
static boolean isBrowser(String userAgent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REST_DECODER

public static PathTrie.Decoder REST_DECODER
Constructor Detail

RestUtils

public RestUtils()
Method Detail

isBrowser

public static boolean isBrowser(@Nullable
                                String userAgent)

decodeQueryString

public static void decodeQueryString(String s,
                                     int fromIndex,
                                     Map<String,String> params)

decodeComponent

public static String decodeComponent(String s)
Decodes a bit of an URL encoded by a browser.

This is equivalent to calling decodeComponent(String, Charset) with the UTF-8 charset (recommended to comply with RFC 3986, Section 2).

Parameters:
s - The string to decode (can be empty).
Returns:
The decoded string, or s if there's nothing to decode. If the string to decode is null, returns an empty string.
Throws:
IllegalArgumentException - if the string contains a malformed escape sequence.

decodeComponent

public static String decodeComponent(String s,
                                     Charset charset)
Decodes a bit of an URL encoded by a browser.

The string is expected to be encoded as per RFC 3986, Section 2. This is the encoding used by JavaScript functions encodeURI and encodeURIComponent, but not escape. For example in this encoding, é (in Unicode U+00E9 or in UTF-8 0xC3 0xA9) is encoded as %C3%A9 or %c3%a9.

This is essentially equivalent to calling URLDecoder.URLDecoder.decode(String, String) except that it's over 2x faster and generates less garbage for the GC. Actually this function doesn't allocate any memory if there's nothing to decode, the argument itself is returned.

Parameters:
s - The string to decode (can be empty).
charset - The charset to use to decode the string (should really be Charsets.UTF_8.
Returns:
The decoded string, or s if there's nothing to decode. If the string to decode is null, returns an empty string.
Throws:
IllegalArgumentException - if the string contains a malformed escape sequence.


Copyright © 2009-2012. All Rights Reserved.