com.linkedin.restli.internal.common
Class AsciiHexEncoding

java.lang.Object
  extended by com.linkedin.restli.internal.common.AsciiHexEncoding

public class AsciiHexEncoding
extends java.lang.Object

This class is used to encode and decode a string using a given encoding char and a set of reserved characters to encode. All reserved characters are encoded to their ASCII hex value and prefixed with the encoding char. The encoding char is also encoded to it's respective ASCII hex value and prefixed with the encoding char. All encoded hex values are decoded to their ascii char value. Percent encoding could, for example, be implemented by using '%' as the escape char and '!', '#', '$', '&' ... as the reserved chars.


Nested Class Summary
static class AsciiHexEncoding.CannotDecodeException
          Defines the exception thrown when the string cannot be decoded
 
Constructor Summary
AsciiHexEncoding(char escapeChar, char[] reservedChars)
           
AsciiHexEncoding(char encodingChar, java.util.Set<java.lang.Character> reservedChars)
          Constructor.
 
Method Summary
 java.lang.String decode(java.lang.String s)
          Decodes the string, .
 java.lang.String encode(java.lang.String s)
          Encodes the incoming string according to the given escape character and reserved characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsciiHexEncoding

public AsciiHexEncoding(char escapeChar,
                        char[] reservedChars)
                 throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

AsciiHexEncoding

public AsciiHexEncoding(char encodingChar,
                        java.util.Set<java.lang.Character> reservedChars)
                 throws java.lang.IllegalArgumentException
Constructor. You provide the set of reserved characters that you want to be encoded. The encoding character is the one you provide.

Parameters:
encodingChar - the character used for encoding
reservedChars - the set of reserved characters to encode
Throws:
java.lang.IllegalArgumentException - if problem with arguments
Method Detail

encode

public java.lang.String encode(java.lang.String s)
Encodes the incoming string according to the given escape character and reserved characters.

Parameters:
s - the string to encode
Returns:
the encoded string

decode

public java.lang.String decode(java.lang.String s)
                        throws AsciiHexEncoding.CannotDecodeException
Decodes the string, .

Parameters:
s - the string to decode
Returns:
the decoded string
Throws:
AsciiHexEncoding.CannotDecodeException - if the string cannot be decoded