Package org.uberfire.java.nio
Class EncodingUtil
- java.lang.Object
-
- org.uberfire.java.nio.EncodingUtil
-
public class EncodingUtil extends Object
The URIUtil class that was available in commons-httpclient 3.x was retired when httpclient moved to the 4.x branch.See http://marc.info/?l=httpclient-users&m=125425095705062&w=2 for more informatoin.
-
-
Field Summary
Fields Modifier and Type Field Description protected static BitSetabs_pathURI absolute path.static BitSetallowed_abs_pathThose characters that are allowed for the abs_path.protected static BitSetalphaBitSet for alpha.protected static BitSetalphanumBitSet for alphanum (join of alpha & digit).protected static BitSetdigitBitSet for digit.protected static BitSetescapedBitSet for escaped.protected static BitSethexBitSet for hex.protected static BitSetmarkBitSet for mark.protected static BitSetparamBitSet for param (alias for pchar).protected static BitSetpath_segmentsBitSet for path segments.protected static BitSetpcharBitSet for pchar.protected static BitSetpercentThe percent "%" character always has the reserved purpose of being the escape indicator, it must be escaped as "%25" in order to be used as data within a URI.protected static BitSetsegmentBitSet for segment.protected static BitSetunreservedData characters that are allowed in a URI but do not have a reserved purpose are called unreserved.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringdecode(String escaped)Unescape and decode a given string regarded as an escaped string with the UTF-8 protocol charset.static StringencodePath(String unescaped)Escape and encode a string regarded as the path component of an URI with the default protocol charset.static byte[]getAsciiBytes(String data)Converts the specified string to byte array of ASCII characters.static StringgetAsciiString(byte[] data)Converts the byte array of ASCII characters to a string.static byte[]getBytes(String data, String charset)Converts the specified string to a byte array.static StringgetString(byte[] data, String charset)Converts the byte array of HTTP content characters to a string.
-
-
-
Field Detail
-
allowed_abs_path
public static final BitSet allowed_abs_path
Those characters that are allowed for the abs_path.
-
percent
protected static final BitSet percent
The percent "%" character always has the reserved purpose of being the escape indicator, it must be escaped as "%25" in order to be used as data within a URI.
-
digit
protected static final BitSet digit
BitSet for digit.digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
-
alpha
protected static final BitSet alpha
BitSet for alpha.alpha = lowalpha | upalpha
-
alphanum
protected static final BitSet alphanum
BitSet for alphanum (join of alpha & digit).alphanum = alpha | digit
-
hex
protected static final BitSet hex
BitSet for hex.hex = digit | "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f"
-
escaped
protected static final BitSet escaped
BitSet for escaped.escaped = "%" hex hex
-
mark
protected static final BitSet mark
BitSet for mark.mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
-
unreserved
protected static final BitSet unreserved
Data characters that are allowed in a URI but do not have a reserved purpose are called unreserved.unreserved = alphanum | mark
-
pchar
protected static final BitSet pchar
BitSet for pchar.pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | ","
-
param
protected static final BitSet param
BitSet for param (alias for pchar).param = *pchar
-
segment
protected static final BitSet segment
BitSet for segment.segment = *pchar *( ";" param )
-
path_segments
protected static final BitSet path_segments
BitSet for path segments.path_segments = segment *( "/" segment )
-
abs_path
protected static final BitSet abs_path
URI absolute path.abs_path = "/" path_segments
-
-
Method Detail
-
encodePath
public static String encodePath(String unescaped)
Escape and encode a string regarded as the path component of an URI with the default protocol charset.- Parameters:
unescaped- an unescaped string- Returns:
- the escaped string
-
getBytes
public static byte[] getBytes(String data, String charset)
Converts the specified string to a byte array. If the charset is not supported the default system charset is used.- Parameters:
data- the string to be encodedcharset- the desired character encoding- Returns:
- The resulting byte array.
-
getAsciiString
public static String getAsciiString(byte[] data)
Converts the byte array of ASCII characters to a string. This method is to be used when decoding content of HTTP elements (such as response headers)- Parameters:
data- the byte array to be encoded- Returns:
- The string representation of the byte array
-
getAsciiBytes
public static byte[] getAsciiBytes(String data)
Converts the specified string to byte array of ASCII characters.- Parameters:
data- the string to be encoded- Returns:
- The string as a byte array.
-
getString
public static String getString(byte[] data, String charset)
Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.- Parameters:
data- the byte array to be encodedcharset- the desired character encoding- Returns:
- The result of the conversion.
-
decode
public static String decode(String escaped)
Unescape and decode a given string regarded as an escaped string with the UTF-8 protocol charset.- Parameters:
escaped- a string- Returns:
- the unescaped string
- Throws:
IllegalStateException- if the escaped string is not a correct URL
-
-