|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.basho.riak.client.util.CharsetUtils
public class CharsetUtils
Utils for dealing with byte[]
, String
charset
issues, especially since Java 5 is less cool than Java 6 in this respect.
This code is mainly from the Trifork fork of the client and was written by
Krestan Krab and/or Erik Søe Sørensen.
Field Summary | |
---|---|
static Charset |
ASCII
|
static Charset |
ISO_8859_1
|
static Charset |
UTF_8
|
Constructor Summary | |
---|---|
CharsetUtils()
|
Method Summary | |
---|---|
static String |
addUtf8Charset(String contentType)
Adds the utf-8 charset to a content type. |
static byte[] |
asBytes(String string,
Charset charset)
Turn a string into an array of bytes using the passed Charset |
static String |
asString(byte[] bytes,
Charset charset)
Turns a byte[] array into a string in the provided Charset |
static String |
asUTF8String(byte[] bytes)
Turns a byte[] array into a UTF8 string |
static Charset |
getCharset(Map<String,String> headers)
Attempt to extract a charset from a Map of HTTP
headers. |
static Charset |
getCharset(String contentType)
Attempts to parse the Charset from a contentType string. |
static String |
getDeclaredCharset(String contentType)
Get the actual string value declared as the charset in a content-type string, regardless of its validity. |
static boolean |
hasCharset(String ctype)
Check if a content-type string has a charset field appended. |
static byte[] |
utf8StringToBytes(String string)
Turn a UTF-8 encoded string into an array of bytes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static Charset ASCII
public static Charset ISO_8859_1
public static Charset UTF_8
Constructor Detail |
---|
public CharsetUtils()
Method Detail |
---|
public static Charset getCharset(Map<String,String> headers)
Map
of HTTP
headers. Really just pulls a the entry
Constants.HDR_CONTENT_LENGTH
from the map and passes it to
getCharset(String)
headers
- a Map
of HTTP headers (or anything, really).
ISO_8859_1
if headers
is null,
or result of calling getCharset(String)
with
the content-type
header from headers
getCharset(String)
public static Charset getCharset(String contentType)
Charset
from a contentType string.
If contentType is null or no charset declaration found, then UTF-8 is
returned. If the found Charset declaration is unknown on this platform
then a runtime exception is thrown.
contentType
-
Charset
parsed from a charset declaration in a
contentType
String.public static String getDeclaredCharset(String contentType)
NOTE: this is different from getCharset, which will always return a default value.
contentType
- the content-type string
public static String addUtf8Charset(String contentType)
contentType
-
contentType
with ;charset=utf-8 appended.public static String asString(byte[] bytes, Charset charset)
Charset
bytes
- charset
-
public static String asUTF8String(byte[] bytes)
bytes
- charset
-
public static byte[] asBytes(String string, Charset charset)
Charset
string
- charset
-
public static byte[] utf8StringToBytes(String string)
string
-
public static boolean hasCharset(String ctype)
ctype
- the content-type string
ctype
has a charset, false otherwise
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |